Abed Aarabi
Abed Aarabi

Reputation: 49

Autodesk Forge viewer PDF extension

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;
}
  }

Upvotes: 2

Views: 273

Answers (2)

K J
K J

Reputation: 11850

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

Upvotes: 1

AlexAR
AlexAR

Reputation: 1324

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

Upvotes: 2

Related Questions