Reputation: 111
I'm currently trying to export a file from the Google Drive API. However, I don't know how to pass the mimeType parameter correctly using fetch. I tried the code below:
function getFile (access_token) {
const fileUrl = "https://www.googleapis.com/drive/v3/files/" + imageID + "/export";
let fileRequest = {
method: "GET",
mimeType: 'image/png',
headers: new Headers({
Authorization: "Bearer " + access_token
})
}
fetch(fileUrl, fileRequest).then( response => {
return(response.json());
}).then( file => {
console.log(file);
});
The error I'm getting is:
Required parameter: mimeType
Upvotes: 0
Views: 74
Reputation: 15377
You should attach the headers using the Headers
class:
function getFile(token, id) {
const url = "https://www.googleapis.com/drive/v3/files/" + id + "/export"
const headers = new Headers()
headers.append('Authorization', `Bearer ${token}`)
headers.append('Content-Type', 'image/png')
let options = {
method: "get",
headers
}
fetch(url, options).then(response => {
// do stuff with response
})
}
As per the Files: export documentation:
Exports a Google Doc to the requested MIME type and returns the exported content. Please note that the exported content is limited to 10MB.
So images are not supported by this endpoint. You will need to use Files: get instead. You can do this simply by removing the '/export
from the end of the URL.
Upvotes: 1