2014-11-11 2 views
0

파일을 업로드 한 다음 해당 파일을 Google 드라이브에 전달하고 싶습니다. Busboy 및 노드 Google 드라이브 클라이언트를 사용 중입니다!노드 : 버스 보이에서 Google 드라이브로 데이터 스트리밍

나는 busboy에서 Google 드라이브 API로 파일 스트림을 전달하려고합니다. 나는 그 임시 파일을 읽기 위해 fs.createReadStream를 임시 파일을 만든 다음 만들려는 그나마

, 나는 그것이 어떤 IO 작업없이 메모리를 사용하여 순수을 수행하는 방법에

어떤 생각을 할 할 그것?

busboy.on('file', function(fieldname, file, filename, encoding, mimetype){ 
    console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype); 

    file.on('data', function(data){ 
     //Need to store all the data here and pass it back at file.on('end')    
    }); 

    file.on('end', function(){ 
     drive.files.insert({ 
      resource: { 
       title: '123.jpg', 
       mimeType: 'image/jpeg', 
       parents: [{ 
        kind: "drive#fileLink", 
        id: "0B0qG802x7G4bM3gyUll6MmVpR0k" 
       }] 
      }, 
      media: { 
       mimeType: 'image/jpeg', 
       body: //how to pass stream from busboy to here??? 
      } 
     }, function(err, data){ 

     }); 
    }) 
}) 

답변

1

googleapis module documentation 따르면, body는 읽을 스트림 또는 문자열로 설정 될 수있다. 따라서 코드는 다음과 같을 수 있습니다.

busboy.on('file', function(fieldname, file, filename, encoding, mimetype){ 
    console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype); 

    drive.files.insert({ 
    resource: { 
     title: '123.jpg', 
     mimeType: 'image/jpeg', 
     parents: [{ 
     kind: "drive#fileLink", 
     id: "0B0qG802x7G4bM3gyUll6MmVpR0k" 
     }] 
    }, 
    media: { 
     mimeType: 'image/jpeg', 
     body: file 
    } 
    }, function(err, data){ 

    }); 
}) 
관련 문제