Thursday, 1 June 2017

node.js read file from URL

I'm trying to upload a file to Google Drive directly from S3 of AWS. The problem I have now is that I can't properly set the url of the file in S3 buckets to fs.readFileSync(path) as the filepath argument. Could you tell me how to fix this problem?

My code looks like this:

    drive.files.insert({
      auth: oauth2Client,
      resource:{
        name:'sample.txt'
      },
      media:{
        mimeType: 'text/plain',
        body: fs.readFileSync('https://s3-ap-northeast-1.amazonaws.com/eto-client-upload/1496061828509test.txt')
      }
    }, function(err,res){
      if(err){
        render('error')
      }else{
        console.log(res)
      }
    });

And I get an error like this:

Error: ENOENT: no such file or directory, open 'C:\Users\User\Desktop\myProject\https:\s3-ap-northeast-1.amazonaws.com\eto-client-upload\1496061828509test.txt'
at Error (native)
at Object.fs.openSync (fs.js:641:18)
at Object.fs.readFileSync (fs.js:509:33)
at C:\Users\User\Desktop\myProject\routes\Login.js:91:22
at C:\Users\User\Desktop\myProject\node_modules\google-auth-library\lib\auth\oauth2client.js:154:5
at Request._callback (C:\Users\User\Desktop\myProject\node_modules\google-auth-library\lib\transporters.js:106:7)
at Request.self.callback (C:\Users\User\Desktop\myProject\node_modules\request\request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (C:\Users\User\Desktop\myProject\node_modules\request\request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage.<anonymous> (C:\Users\User\Desktop\myProject\node_modules\request\request.js:1091:12)
at IncomingMessage.g (events.js:292:16)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)

I'd really appreciate your help. Thank you.



via Kenyo

No comments:

Post a Comment