How to upload file type in nodejs googleapis (in express multer)
See original GitHub issueI have a problem in uploding pdf file from from fontend in Nodejs so the problem is how to convert file type to correct form to upload to google drive
my file type is like this
{ fieldname: ‘file’, originalname: ‘test.pdf’, encoding: ‘7bit’, mimetype: ‘application/pdf’, buffer: <Buffer 25 50 44 46 2d 31 2e 34 0a 25 20 e2 e3 cf d3 0a 34 0a 30 0a 6f 62 6a 0a 3c 3c 0a 2f 54 79 70 65 0a 2f 43 61 74 61 6c 6f 67 0a 2f 4e 61 6d 65 73 0a 3c … >, size: 150251 }
and my code is like this ` const {google} = require(‘googleapis’) const drive = google.drive(‘v3’)
const app = express()
const upload = multer()
app.post(
'test-upload-pdf-file',
upload.single('file'),
(req, res, next) => {
drive.files.create({
resource: { mimeType: 'application/pdf'},
media: {mimeType: 'application/pdf', body: req.file.buffer},
fields: 'id'
}, function (err, file) {
}
)`
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:30 (1 by maintainers)
Top Results From Across the Web
How to Upload Files to Google Drive with Node.js, Express ...
This tutorial explains how you can upload files to Google Drive that are submitted through a web form and encoded as multipart/form-data.
Read more >Uploading Files Using Multer in a Node.js Application
In this article, we will see how to use Multer to handle multipart/form-data using Node.js, Express and MongoDB.
Read more >Multer: Easily upload files with Node.js and Express
Encoding and uploading forms with Multer ; enctype attribute, which specifies how data should be encoded by the browser before sending it to...
Read more >Google Cloud Storage with Node.js: File Upload example
Open command prompt, change current directory to the root folder of our project. Install GCS, Express, Multer, CORS modules with the following ...
Read more >Google drive API upload file with Nodejs + service account
The Google Drive api allows us to create and upload the binary type files directly to Google drive with Node js. The Google...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, @Thammawat I did it the following way. It worked for me. Let me know if it works for you.
Good to know. Keep up doing Interesting things!