The web component cannot use multipart, therefore we have to send two web calls, the first (POSTFile) to upload the actual file (which is untitled and goes to the root folder of Google Drive), the second (PATCHtext) to send the metadata (filename, folderId) which correctly names the file, and moves it to the designated folder.
Thank you, Taifun. However, it appears that the block patch is not available. I attempted to use the ‘put’ method, but it didn’t work as expected. Currently, I have two additional approaches:
Utilize AppScript.
Implement the method of sending the image by converting it to Base64.
Could you please provide further guidance or suggest an alternative solution?
1. Setup Google Apps Script for Handling File Uploads
Google Apps Script Code
javascript
function doPost(e) {
try {
var folderId = "YOUR_FOLDER_ID"; // Replace with your Google Drive folder ID
var folder = DriveApp.getFolderById(folderId);
var params = e.parameter;
var fileBlob = e.postData.getBlob();
var newFileName = params.filename || "default_name"; // Get filename from request or use default
// Create file in the specified folder with the new name
var file = folder.createFile(fileBlob).setName(newFileName);
return ContentService.createTextOutput(JSON.stringify({
success: true,
fileId: file.getId(),
fileName: file.getName(),
fileUrl: file.getUrl()
})).setMimeType(ContentService.MimeType.JSON);
} catch (error) {
return ContentService.createTextOutput(JSON.stringify({
success: false,
error: error.toString()
})).setMimeType(ContentService.MimeType.JSON);
}
}
2. Deploy as a Web App
In Google Apps Script, click Deploy > New Deployment.
Select Web app.
Set Who has access to “Anyone” (or “Anyone with the link”).
Copy the provided Web App URL.
3. Make a POST Request Using “Call Web1 Post file”