Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use cURL to stream upload a file using POST?

Tags:

php

curl

Or does PHP not allow this? I have read it is possible using PUT but the server is expecting POST only.

like image 821
Ross Logan Avatar asked Apr 12 '13 10:04

Ross Logan


People also ask

How do I upload a file using Curl POST?

How to send a file using Curl? To upload a file, use the -d command-line option and begin data with the @ symbol. If you start the data with @, the rest should be the file's name from which Curl will read the data and send it to the server. Curl will use the file extension to send the correct MIME data type.

Can Curl upload files?

Uploading files using CURL is pretty straightforward once you've installed it. Several protocols allow CURL file upload including: FILE, FTP, FTPS, HTTP, HTTPS, IMAP, IMAPS, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, and TFTP. Each of these protocols works with CURL differently for uploading data.

How do I send contents as body entity with Curl?

cURL Specify Content-Type The Content-Type entity in the header specifies the type of media of the resource we are sending. The media type is also commonly known as the MIME Type. To specify the Content-Type in a cURL request, we can use the -H flag. For example, let us send MIME Type of application/JSON.

What is data binary in Curl?

--data-binary is a curl SPECIFIC flag for curl itself. it has nothing to do with HTTP web services call specifically, but it's how you "POST" data to the call in the HTTP BODY instead of in the header WHEN using curl.


1 Answers

cURL has already support for streams, try curl --help | grep binary and you will get:

--data-binary DATA HTTP POST binary data (H)

An example:

curl -v -XPOST http://example:port/path --data-binary @file.tar
-H "Content-Type: application/octet-stream"

like image 126
hukeping Avatar answered Oct 22 '22 01:10

hukeping