我想构造一个POST,如下面的链接所述GoogleDriveMultipartUpload到目前为止我一直在使用axios,但它不支持multipart/related类型。有没有变通的办法或更直接的解决方案。
vvppvyoh1#
这在axios中是不可能的,因为它是doesn't allow multipart requests。但是,您可以使用Google云端硬盘节点库,如下所述:
/** * Insert new file. * @return{obj} file Id * */ async function uploadBasic() { const fs = require('fs'); const {GoogleAuth} = require('google-auth-library'); const {google} = require('googleapis'); // Get credentials and build service // TODO (developer) - Use appropriate auth mechanism for your app const auth = new GoogleAuth({ scopes: 'https://www.googleapis.com/auth/drive', }); const service = google.drive({version: 'v3', auth}); const requestBody = { name: 'photo.jpg', fields: 'id', }; const media = { mimeType: 'image/jpeg', body: fs.createReadStream('files/photo.jpg'), }; try { const file = await service.files.create({ requestBody, media: media, }); console.log('File Id:', file.data.id); return file.data.id; } catch (err) { // TODO(developer) - Handle error throw err; } }
字符串
1条答案
按热度按时间vvppvyoh1#
这在axios中是不可能的,因为它是doesn't allow multipart requests。
但是,您可以使用Google云端硬盘节点库,如下所述:
字符串