iLexDev/ASP.NET-WebApi-MultipartDataMediaFormatter

Google app script Form-data post

Closed this issue · 1 comments

Currently having an issue sending a form-data post via Google App script language. Here is an example of what the a request looks like.

// Make a POST request with form data. var resumeBlob = Utilities.newBlob('Hire me!', 'text/plain', 'resume.txt'); var formData = { 'name': 'Bob Smith', 'email': 'bob@example.com', 'resume': resumeBlob }; // Because payload is a JavaScript object, it will be interpreted as // as form data. (No need to specify contentType; it will automatically // default to either 'application/x-www-form-urlencoded' // or 'multipart/form-data') var options = { 'method' : 'post', 'payload' : formData }; UrlFetchApp.fetch('https://httpbin.org/post', options);

which generates:

`-------zDHRO6exmjp3GUEz3UjmRoiGYiShqfANvFZda3pXuDNj0hWtAF
Content-Disposition: form-data; name="account_ref.id";

9b639ebe-b574-4054-b818-95a10fd3ce15
-------zDHRO6exmjp3GUEz3UjmRoiGYiShqfANvFZda3pXuDNj0hWtAF
Content-Disposition: form-data; name="content_type";

text/plain
-------zDHRO6exmjp3GUEz3UjmRoiGYiShqfANvFZda3pXuDNj0hWtAF
Content-Disposition: form-data; name="size";

1134
-------zDHRO6exmjp3GUEz3UjmRoiGYiShqfANvFZda3pXuDNj0hWtAF
Content-Disposition: form-data; name="file_name";

test.png
-------zDHRO6exmjp3GUEz3UjmRoiGYiShqfANvFZda3pXuDNj0hWtAF
Content-Disposition: form-data; name="description";

uploaded from gmail add on.
-------zDHRO6exmjp3GUEz3UjmRoiGYiShqfANvFZda3pXuDNj0hWtAF
Content-Disposition: form-data; name="matter_ref.id";

9b639ebe-b574-4054-b818-95a10fd3ce15
-------zDHRO6exmjp3GUEz3UjmRoiGYiShqfANvFZda3pXuDNj0hWtAF
Content-Disposition: form-data; name="names"; filename="t.txt"
Content-type: text/plain

https://localhost:44383/settings/lawpayredirect

https://hookb.in/EJOOBmz2

Concerns:

{
"id": "N0DbatMOTjm8FuPRTKm0uA",
"created": "2016-07-01T01:55:12.468Z",
"type": "recurring_charge.created",
"data": {
"id": "DUPzt5y7RVGmnSW4BJegbQ",
"status": "ACTIVE",
"account_id": "D5qNOhlwSNK7IV2-HtSAdA",
"method": {
"type": "card",
"number": "************4242",
"fingerprint": "GunPelYVthifNV63LEw1",
"card_type": "VISA",
"exp_month": 10,
"exp_year": 2022,
"name": "Test Customer",
"address1": "123 Main St",
"postal_code": "78730"
},
"schedule": {
"interval_unit": "MONTH",
"interval_delay": 1,
"start": "2020-01-01"
},
"description": "New Recurring Charge",
"amount": 145,
"currency": "USD",
"total_occurrences": 0,
"total_amount": 0,
"next_payment": "2020-01-01"
}
}
-------zDHRO6exmjp3GUEz3UjmRoiGYiShqfANvFZda3pXuDNj0hWtAF--`

but I get this exception.
MultipartDataMediaFormatter.Converters.HttpContentToFormDataConverter.IsFile(ContentDispositionHeaderValue disposition) at MultipartDataMediaFormatter.Converters.HttpContentToFormDataConverter.<Convert>b__8(HttpContent x) at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext()
at MultipartDataMediaFormatter.Converters.HttpContentToFormDataConverter.d__a.MoveNext()`

Making the same request via postman to the same endpoint works just fine.

sorry for the late reply, but if using postman you don't have the problem it looks like something wrong with a request format. to be sure I would recommend you to create regular mvc controller's action (not web api) and test this request. maybe it will show more error information