2

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;
}
  }
Abed Aarabi
  • 51
  • 1
  • 5
  • so that mean i have 100 client and each of them has some pdf files i will end up with 1000s of files most be download to local? Is any code example with i can look at? – Abed Aarabi Mar 16 '23 at 20:40

2 Answers2

2

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().

AlexAR
  • 1,052
  • 1
  • 9
  • 15
1

When a PDF in in the web It MUST Download 1st to be viewed by the client. Then it can be edited into pixels, to show the contents.

The client user either pre-sets the download to be returned to the viewing extension e.g. a browsers viewer or an external viewer or save to a download folder, for editing there. There is no avoiding the NEED for a download. (You could programmatically write the file to a memory IO FileSystem, However that's not Guaranteed see ** below.)

enter image description here

enter image description here

** Not specific to this group of users but here are some statistics, granted unqualified. https://gs.statcounter.com/platform-market-share/desktop-mobile-tablet

  • 60% of browsers are mobile, 38% desktop, 2% other.
  • over 66% users use Googles Chromium based browsers.
  • Chrome for Android did not have enough power, to show a PDF inside the browser, the usual workaround is to use google viewer servers to view a remote Web URL

However Chromium based MSEdge for Android, reputedly has a MiniPDF viewer extension.

Comments included how do systems like BIM360 appear to work in the cloud, and there the method is not so clear, generally it is only one of two, Either the DocumentManagement system is editing in the cloud server using SAAS, and sending images and text (NOT the PDF) or there is a separate local PDF API handler that sandboxes and manages the localised colaborative download (possibly just a streamed part of a PDF).

K J
  • 8,045
  • 3
  • 14
  • 36
  • the best solution is to write the file into the memory, so the user won't download it file to local, as I asked before is there any code examplee i could look at as reference? – Abed Aarabi Mar 16 '23 at 20:48
  • Unfortunately, it won't work. the app idea is store the pdfs file in a cloud service and do measure and store it in cloud database. I am wonder how BIM360 can ready and draw on top of the files even it stored in S3 bucket! – Abed Aarabi Mar 16 '23 at 20:56