curl upload files??

i have read some posts mentioning curl and i dont know what it does. I need to be able to do the follwoing.

I have a website that lets me upload an image and image information to a database.

It is split into two forms and two asp scripts.

The first form only has two fields, one a ref number field that increments by one and the other field is of type file, with a browse button next to it.

once you submit the filename that was inserted intot he second field is uploaded, then the second form is displayed.

This form has all the infrmation and i can upload all that dynamically using openURl from IE.

My question is can Curl or any other method do what is required in form 1 when i run the script.

The idea is to open an image, let the script goto form one upload that path or filename and then upload the information, the image should then close and open the next file in the folder.

Can this be done? if so how and by what means.

Hi Dave, you can open the Terminal.app (it’s in your Utilities Folder) and type in this command…

man curl

That will open the manual page with instructions on how to use ‘curl’. Use the ‘space bar’ to advance thru the pages or type ‘q’ to exit.
If you plan to use ‘curl’ with AppleScript you’ll need to use the ‘do shell script’ or ‘do script’ command.

have read the manual but dont really understand lots and lots.

with IE and openURL is quite straight forward i can’t seem to understand how to do the same with curl.

i also dont know how to write it.

is this close:

curl -d insert=image -d caption=hello
i understand that is
insert=image&caption=hello

but how do i add it to the end of a url and how do i add the filename

is id something like
curl -d filename=path:to:file -url www.hello.co.uk/

I haven’t used ‘curl’ to upload files, but there is a web site that might be of some help to you…

http://curl.haxx.se/docs/readme.curl.html

It looks like you use…

curl -T - http://www.upload.com/myfile

i have looked at the site and used their example to have a go.

curl -F “file=@Shared G4 HD:Users:karrenmay:Desktop:web pics:009279-DA.jpg” -F “imageno=104318” http://www.bl…es.com/admin/libadd.asp

but i get


error: access denied

does anypone know why this is? i am doing it ina terminal and haven’t though tabout putting it in applescript as i didnt think that it would make a difference

Separating your code would help. Also, curl is a shell command, and doesn’t use colons (:slight_smile: in its paths, it uses slashes.

So, something like this might help.


set myImageFile to "Shared G4 HD:Users:karrenmay:Desktop:web pics:009279-DA.jpg"

set myImageNumber to "104318"

set actionURL to "http://www.bl....es.com/admin/libadd.asp"

set shellCommand to "curl -F 'file=@'" & POSIX path of myImageFile & "' -F 'imageno=" & myImageNumber & "' '" & actionURL & "'"
-- so it is "curl -F 'file=@'/Volumes/Shared G4 HD/Users/karrenmay/Desktop/web pics/009279-DA.jpg' -F 'imageno=104318' 'http://www.bl....es.com/admin/libadd.asp'"

do shell script shellCommand

If the basic frame of your code was correct, this will fix the problem. I haven’t done this before (multipart/form-data), so I’m not the rest is correct, although it seems to fit with the example on the curl website.

Good Luck!

PS. If Shared G4 HD is a startup disk, the the Posix Path will actually NOT show it, since it is the top-level thing. Your Posix Path would then be /Users/karrenmay/Desktop/web pics/009279-DA.jpg

have tried what you said, changing the path of the filename and the image number, as more files have already been uploaded and different files too.

This is the result i get, i dont really know what it means and hope that someone might


sh: -c: line 1: unexpected EOF while looking for matching `''
sh: -c: line 2: syntax error: unexpected end of file

I am guessing that there is a ’ missing but can’t see it.
The code now is


set myImageFile to "Shared G4 HD:Users:karrenmay:Desktop:web pics:000126-DW.jpg"

set myImageNumber to "104759"

set actionURL to "http://www.bluegreenpictures.com/admin/libadd.asp"

set shellCommand to "curl -F 'file=@'" & POSIX path of myImageFile & "' -F 'imageno=" & myImageNumber & "' '" & actionURL & "'"
-- so it is "curl -F 'file=@'/Volumes/Shared G4 HD/Users/karrenmay/Desktop/web pics/009279-DA.jpg' -F 'imageno=104318' 'http://www.bl....es.com/admin/libadd.asp'" 
display dialog shellCommand
try
	do shell script shellCommand
on error thisError
	set the clipboard to thisError as string
	display dialog "The following error occured: " & thisError
end try

Any idseas

editted:---------

have changed the code, found the stray ’ but i now get a new error:


curl: (1) Unsupported protocol: pics/000126-DW.jpg -F imageno=104759 http

Any ideas???

the stray ’ was before the file=@ so added on just at the end.

Right, the problem is that the Posix path of myImageFile has spaces in it, which is why it would need to be quoted. Problem is that it is already in a quoted section of the command. Two ways to fix this: one is to change directories to where the files are, and make sure none of those files have spaces (or other characters that confuse a shell command) and just use the file’s name, not its whole path.

The other way looks like it will work. You don’t need quotes around the file=@ part, so the command would look like this:


set shellCommand to "curl -F file=@" & quoted form of POSIX path of myImageFile & " -F 'imageno=" & myImageNumber & "' '" & actionURL & "'"
--> curl -F file=@'/Shared G4 HD/Users/karrenmay/Desktop/web pics/000126-DW.jpg ' -F 'imageno=104318' 'http://www.bl....es.com/admin/libadd.asp'

I believe that will work.


set myImageFile to "Shared G4 HD:Users:karrenmay:Desktop:web pics:000401-OVW.jpg"

set myImageNumber to "104897"

set actionURL to "http://www.bl....es.com/admin/libadd.asp"

set shellCommand to "curl -F file=@'" & quoted form of POSIX path of myImageFile & "' -F 'imageno=" & myImageNumber & "' '" & actionURL & "'"
-- so it is "curl -F 'file=@'/Volumes/Shared G4 HD/Users/karrenmay/Desktop/web pics/009279-DA.jpg' -F 'imageno=104318' 'http://www.bl....es.com/admin/libadd.asp'" 
display dialog shellCommand
try
	do shell script shellCommand
on error thisError
	set the clipboard to thisError as string
	display dialog "The following error occured: " & thisError
end try

Have tried that and it seems to get furthur, but i have one last error which i am wondering if you know of a way to get round.


"Error: Access is Denied."

I am guessing its because i need authentification, didn’t know if i could trick it or what. Any ideas?

This would help my life lots and lots if i could get it working. Thanks so far.

There’s no trick - if you need to authenticate, look at the man page for curl:


-u/--user <user:password>
              Specify user and password to use when fetching. See
              README.curl  for  detailed  examples  of how to use
              this. If no password is specified,  curl  will  ask
              for it interactively.

i have tried that but no luck.

Do you know of another way in which i could do this, or do you know why i might be getting this error, i think the authentification is working, i am doing -u user:pass just before the action url, which was wrong, sorry to add.

Do i need to press the submit button, the curl.haxx website mehntioned it but i cant seem to get it going.

hmmmmmm.

Really stuck.

Could it be because the form might be in frames? ← its not so dont worry

do you know of a curl forum or any good resources? i have tried the haxx page and it has helped me understand but still wont work.

Cheers