Multipart request without image file - json

I want to call multipart service without uploading an image file. It only has input JSON data.
Is it possible to call multipart service with only JSON & file is optional?

it's absolutely possible to make a valid Multipart/form-data request without any files in, yes.
here is a HTTP Post request with multipart/form-data containing only the variable "foo" with the value "bar":
POST / HTTP/1.1
Host: 127.0.0.1:9999
User-Agent: curl/7.59.0
Accept: */*
Content-Length: 141
Content-Type: multipart/form-data; boundary=------------------------c6d530a086d1167c
--------------------------c6d530a086d1167c
Content-Disposition: form-data; name="foo"
bar
--------------------------c6d530a086d1167c--
generated with the curl command
curl -F "foo=bar" http://127.0.0.1:9999

Related

Is a batch operation to save a set of navigation properties possible?

For example: Company has Employees.
By posting to odata.svc/Company(1)/Employees/$ref, I can save Company-Employee relation. Can I save multiple Company-Employee links this way using odata.svc/Company(1)/Employees/$ref/$batch ?
I tried but didnt work. If this is incorrect way, is there any other alternative ?
OData does support batching, I'm not sure what version of OData you are using but here is some documentation from v3 (v4 is the same) http://www.odata.org/documentation/odata-version-3-0/batch-processing/
In your example batch URL, you are adding $batch to the end of the URL that you are using, instead you have to POST to odata.svc/$batch with a request that contains details of all of the operations that you want to perform. For example, here is one of the request taken from that link:
POST /service/$batch HTTP/1.1 Host: host Content-Type:
multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b
--batch_36522ad7-fc75-4b56-8c71-56071383e77b Content-Type: multipart/mixed;
boundary=changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621
Content-Length: ###
--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621 Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 1
POST /service/Customers HTTP/1.1 Host: host Content-Type:
application/atom+xml;type=entry Content-Length: ###
--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621 Content-Type: application/http Content-Transfer-Encoding: binary
POST $1/Orders HTTP/1.1 Host: host Content-Type:
application/atom+xml;type=entry Content-Length: ###
--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621--
--batch_36522ad7-fc75-4b56-8c71-56071383e77b--

XMLHttpRequest Header : Decode Binary Data Upon Server Arrival

I am building a multipart/form-data httprequest, using Javascript's XMLHttpRequest object. Here are the headers:
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.5
Content-Length: 38539
Content-Type: multipart/form-data; charset=UTF-8; boundary=CONTENT_BOUNDARY
Cookie: __utma=111872281.167592067.1396133699.1396133699.1396133699.1; PHPSESSID=ea7cfjgi8e29v1bhnrj580vbc2
DNT: 1
Host: localhost:90
Referer: localhost:90/my_secret_referer/no_peeking.php
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0
I send the request to a PHP document.
In the following snippet one can observe a part of the request body. It details the transmission of binary data in base64 representing an image file that has been selected.
--CONTENT_BOUNDARY
Content-Disposition: form-data; name="images[]"; filename="airplane.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
.../9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDABkRExYTEBkWFBYcGxkeJT4pJSIiJUw3Oi0...
This body part cooperates with the entire request to create a successful AJAX request to my server. When the information arrives at the server, I decode the information and do what I may with it.
The segment of this process that I am unsatisfied with is the manual decoding of the binary data. One is always able to receive uploaded images in the server as complete, legible image files when using jQuery's $.ajax() or Malsup's jQuery Form. I have looked into the format of the two mentioned requests and have found that they too send binary information using a multipart/form-data request. The one difference that I have found which I have not intentionally made is that my request is furnished with a
charset: utf8;
specification inside of the Content-Type after I send it.
Can I, and if I can, how can I tell the server to decode the binary information it receives?

Get http post request body in perl

Request header (from Firebug):
Accept application/json, text/plain, */*
Accept-Encoding gzip, deflate
Content-Type application/json;charset=utf-8
Request json:
{"key":"value"}
So how to get request body in perl?
What webserver?
Usually POST data is available by simply reading from STDIN.
If you are using the venerable CGI module (under mod_perl or not), you can get the body via:
$cgi->param('POSTDATA')
(if, as in this case, the content type isn't application/x-www-form-urlencoded or multipart/form-data)

multipart/mixed HTTP request in actionscript

Is there an easy way to make an multipart/mixed HTTP request in as3?
I'm trying to reach LightSwitch server using OData protocol from flash. To send multiple commands at once you can combine them in one batch using HTTP request with "multipart/mixed" content type.
Here an example of HTTP requests with two commands:
Content-Type:multipart/mixed; boundary=batch
--batch
Content-Type: multipart/mixed; boundary=changeset
--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary
PUT http://localhost:18065/ApplicationData.svc/Orders(3)/$links/User HTTP/1.1
Content-Type: application/json;odata=verbose
{"uri": "http://localhost:18065/ApplicationData.svc/Users(4)"}
--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary
MERGE http://localhost:18065/ApplicationData.svc/Users(3) HTTP/1.1
Content-Type: application/json;odata=verbose
If-Match: W/"X'0000000000002715'"
{"Name": "User 3_"}
--changeset--
--batch--
Every part contains own HTTP headers and body. Response formatted the same way, with own http response code.
How to work with multiple HTTP requests in actionscript?

how to send form data in a programmatic file upload in box api 2.0

Is the following a correct example of the form POST data in a file upload in the box api 2.0? The documentation says that the 'filename' form field is a string but when sending the post data in, say, python, you need to actually send the file contents in the post. So, is the content-disposition: form-data line below the correct way to name the 'filename' field and include the file contents?
Content-type: multipart/form-data, boundary=AaB03x
Content-length: 142
Authorization: BoxAuth api_key=MY_API_KEY&auth_token=MY_AUTH_TOKEN
--AaB03x
content-disposition: form-data; name="filename"; filename="test.txt"
Content-type: text/plain
testing box api 2.0
--AaB03x--
Yes, that is the correct way to do it.
You mention Python, although you don't mention as being a requirement.
If you can use Ruby (another scripting language) you have a very nice lib to deal with Box API at the 2.0 version.
The lib is named ruby-box and in the readme you can find how to use it.
-------boundary
Content-Disposition: form-data; name="filename"; filename="82b.gif"
Content-Type: image/gif
Content-Transfer-Encoding: BASE64
$base64_encoded_binary_file_content
-------boundary
Content-Disposition: form-data; name="parent_id"
123456789
-------boundary--
This is working code.