Using Google Drive APIs with hURL

Discuss about plugins that don't have a dedicated forum
Post Reply
PEB
Posts: 569
Joined: Sun Feb 21, 2010 1:28 am

Using Google Drive APIs with hURL

Post by PEB »

Has anyone successfully uploaded files to Google Drive with hURL?

I have success using the following cURL command on a Windows terminal:

Code: Select all

curl -X POST -L -H "Authorization: Bearer <AccessToken$>" -F "metadata={name : 'backup.zip', mimeType : 'application/json'};type=application/json;charset=UTF-8" -F "file=@Test.zip;type=application/json" "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart"
But whenever I try doing this with hURL, the file gets uploaded but is always called "Untitled."

This is the code that I'm currently using:

Code: Select all

e = hurl.Easy()
m = e:MIME()
p = m:AddPart()
p:Name("metadata")
p:Data("{name : Backup.zip}")
p:Type("application/json;charset=UTF-8")
p = m:AddPart()
p:Type("application/json")
p:FileData("Ram:Test.zip")
p:FileName("Backup.zip")

e:SetOpt_MIMEPost(m)
e:SetOpt_URL(URL$)
e:SetOpt_httpheader({
	"Authorization: Bearer "..AccessToken$.."", "Content-Type: application/octet-stream",
	})
e:Perform()
e:Close()
m:Free()
Any ideas about how I can include the needed metadata for the uploaded file to have the correct name?
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Using Google Drive APIs with hURL

Post by airsoftsoftwair »

Have you tried using

Code: Select all

p:Data("{name : 'backup.zip', mimeType : 'application/json'}")
instead of

Code: Select all

p:Data("{name : Backup.zip}")
? Not sure if it makes a difference but at least your Hollywood code doesn't resemble the cURL command in that line. So maybe it solves the problem...
Post Reply