Currently, I am working on an app that utilizes the Forge Viewer PDF extension to view PDF drawings in a local environment. Everything works great if the files are stored in local storage. However, I have created an AWS S3 bucket to store the files and attempted to load the .pdf file directly from S3, but unfortunately, it did not work.
I am now wondering if there is a way to load the PDF files directly from the S3 bucket.
viewer.current.loadModel(
"https://easy-cost.s3.eu-north-1.amazonaws.com/12390009",
{},
// @ts-ignore
onDocumentLoadSuccess,
onDocumentLoadFailure
);
viewer?.current?.start();
Backend:
async uploadFile(file: Express.Multer.File, key?: string): Promise<string> {
const bucket = this.configService.get<string>('S3_BUCKET');
const input: PutObjectCommandInput = {
Body: file.buffer,
Bucket: bucket,
Key: key,
ContentType: file.mimetype,
ACL: 'public-read',
};
console.log(this.configService.get<string>('S3_accessKeyId'), '000000');
try {
const response: PutObjectCommandOutput = await this.s3.send(
new PutObjectCommand(input),
);
if (response.$metadata.httpStatusCode === 200) {
return `https://${bucket}.s3.${this.region}.amazonaws.com/${key}`;
}
throw new Error('Image not saved in s3!');
} catch (err) {
this.logger.error('Cannot save file to s3,', err);
throw err;
}
}
I managed to make it working with a S3 url from bucket. The url I used had the extension, something like : https://[my-bucket].s3.eu-west-3.amazonaws.com/[filename].pdf
that I obtained with the CopyUrl function of the S3 Console.
Also you should use viewer.start([your-file-url])
instead of viewer.loadModel()
.