0

I was wondering if there's a way to upload a .doc, .pdf, or .zip file to cloudinary. I got the data from the client using multer and i recieve something like this, for example:

  fieldname: 'file',
  originalname: 'F12se.zip',
  encoding: '7bit',
  mimetype: 'application/x-zip-compressed',
  buffer: <Buffer 50 4b 03 04 14 00 00 00 08 00 90 68 aa 50 ad bd d9 53 13 05 00 00 c5 0a 00 00 0d 00 00 00 43 68 61 6e 67 65 6c 6f 67 2e 74 78 74 9d 56 eb aa d3 40 10 ... 1864943 more bytes>,
  size: 1864993

I guess I have to do something with the buffer, but I'm not sure as to what or how.

Any help would be appreciated. Thanks.

1

2 Answers 2

1

I work on Cloudinary's Customer Success team, and while we don't have any example code with multer uploads, if you save the contents of the buffer as a file, you can then upload it to Cloudinary as a raw resource_type with

cloudinary.v2.uploader.upload("filename.ext", 
  { resource_type: "raw" }, 
  function(error, result) {console.log(result, error); });

as per https://cloudinary.com/documentation/upload_images#uploading_non_media_files_as_raw_files

If you need further assistance, you're welcome to raise a ticket via our Support Center over at https://support.cloudinary.com/hc/en-us/requests/new

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Danny V. Thanks for your reply, however I got an error "TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Buffer" after trying your fix and instead of "filename.ext" I put file.buffer
0

Are you on the free or paid version of Cloudinary? Looking at your code everything seems to be ok.

Please note that PDFs and some archive formats such as zip, rar and tagz are, by default, blocked for delivery for FREE accounts in order to reduce the chances of malware or other potentially harmful files being distributed via the Cloudinary domain. Here's a link for refference

1 Comment

I solved the problem by using a package called "buffer-to-data-url". I converted the buffer to a uri and then saved it to clodudinary. Another issue I had was with the file extensions after uploading to cloudinary, I fixed that with using "filename_override: file.originalname" and "resource_type: 'auto'".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.