multipartform-data

Serializing Multipart Form requests for testing on Play 2.1

三世轮回 提交于 2019-12-02 01:59:43
问题 I'm working on play2.1 writing a test for a post controller that uses multipart forms using the route function. route( FakeRequest(POST, postControllerRoute().url, FakeHeaders(Seq(HeaderNames.CONTENT_TYPE -> Seq("multipart/form-data"))), body = body ).withAuthToken.withAdmin(adminId)) I've found that for this code to work I need to define a writeable of this type Writeable[MultipartFormData[TemporaryFile]] since my body variable is of type MultipartFormData[TemporaryFile]. I'm not sure how to

Uploading file without multipart/form-data (server to server)

巧了我就是萌 提交于 2019-12-02 01:27:32
From this answer https://stackoverflow.com/a/1695287/256400 , I get the feeling that multipart/form-data is needed to upload file from browser to server. But if my use case is to upload file from server to server shouldn't it work if I put the Content-Type as application/octet-stream or even specific types like image/png I was experimenting with this on a node.js server and used fs.readFile to get the file content and used a REST library to do HTTP POST. But I am a bit confused on the encoding to be used when reading the file. Be default fs.readFile returns Buffer object. I was tempted to use

Serializing Multipart Form requests for testing on Play 2.1

喜你入骨 提交于 2019-12-02 00:50:05
I'm working on play2.1 writing a test for a post controller that uses multipart forms using the route function. route( FakeRequest(POST, postControllerRoute().url, FakeHeaders(Seq(HeaderNames.CONTENT_TYPE -> Seq("multipart/form-data"))), body = body ).withAuthToken.withAdmin(adminId)) I've found that for this code to work I need to define a writeable of this type Writeable[MultipartFormData[TemporaryFile]] since my body variable is of type MultipartFormData[TemporaryFile]. I'm not sure how to serialize a multipart request or if this is even the right approach. Any suggestions? Edited Answer:

org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException

回眸只為那壹抹淺笑 提交于 2019-12-01 23:38:59
问题 How to handle java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field fileName exceeds its maximum permitted size of 3145728 bytes. This happens after uploading a file which is bigger than maxFileSize limit in servlet @MultipartConfig. Is there a way to load in browser custom error page or something else because after that client recievs The connection was reset 回答1: I'm guessing the normal servlet error-page mechanism

org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException

半世苍凉 提交于 2019-12-01 21:16:55
How to handle java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field fileName exceeds its maximum permitted size of 3145728 bytes. This happens after uploading a file which is bigger than maxFileSize limit in servlet @MultipartConfig. Is there a way to load in browser custom error page or something else because after that client recievs The connection was reset I'm guessing the normal servlet error-page mechanism should catch this, so add this to web.xml : <error-page> <error-code>500</error-code> <location>

Convert cURL request to Python-Requests request

[亡魂溺海] 提交于 2019-12-01 20:59:42
I want to convert this cURL request to a Python-Requests request since I am working on a Python wrapper for a REST service MS_WORD_DOCUMENT=... CONTENT_TYPE="application/msword" JSON_REQUEST="{\"documentType\" : \"$CONTENT_TYPE\"}" curl -X POST -F "meta=$JSON_REQUEST;type=application/json" -F "data=@$MS_WORD_DOCUMENT" $SERVICE_ENDPOINT How can I convert this to a Python3 Requests library request? So far I've got to data = {"metadata": {"documentType": "application/msword", "Content-Type": "application/json"}} req = requests.post( "https://text.s4.ontotext.com/v1/twitie", auth=("user", "pass"),

What are valid characters for creating a multipart form boundary?

本秂侑毒 提交于 2019-12-01 14:07:09
问题 In an HTML form post what are valid characters for creating a multipart boundary? 回答1: According to RFC 2046, section 5.1.1: boundary := 0*69<bchars> bcharsnospace bchars := bcharsnospace / " " bcharsnospace := DIGIT / ALPHA / "'" / "(" / ")" / "+" / "_" / "," / "-" / "." / "/" / ":" / "=" / "?" So it can be between 1 and 70 characters long, consisting of alphanumeric, and the punctuation you see in the list. Spaces are allowed except at the end. 回答2: There are no rules as of the content of

Posting an object and a file in the same call to the server with jQuery.ajax

旧街凉风 提交于 2019-12-01 12:17:42
I'm trying to make a client side post to the following MVC action method: [HttpPost] public void Create(ProductModel product, HttpPostedFileBase imageFile) { productServices.AddProduct(product, imageFile); } This is straightforward with a type="submit" button, however in my particular case I need to do it with an ajax call. I can just pass the ProductModel as JSON easy enough. $.ajax({ url: '/Product/Create', type: 'POST', data: JSON.stringify({product: { Id: 1, Name: "SomeName" } }), contentType: 'application/json; charset=utf-8', success: function (data) { alert("Product Created!"); } }); I

How to do multipart/form-data post request with Swift?

被刻印的时光 ゝ 提交于 2019-12-01 11:50:16
let Url = String(format: "http://url/ios.php") guard let serviceUrl = URL(string: Url) else { return } let parameterDictionary :[String:String] = ["Episodes" : "http://url/anime/07-ghost.html"] var request = URLRequest(url: serviceUrl) request.httpMethod = "POST" request.setValue("multipart/form-data", forHTTPHeaderField: "Content-Type") request.httpBody = NSKeyedArchiver.archivedData(withRootObject: parameterDictionary) let session = URLSession.shared session.dataTask(with: request) { (data, response, error) in if let response = response { print(response) } if let data = data { do { let json

How to upload an image using alamofire multipart form data with basic authentication?

我只是一个虾纸丫 提交于 2019-12-01 11:31:06
问题 I am new in programming and in iOS development. I need to upload an image using Alamofire multipart form data, but I also need to input basic authentication header. in this thread Alamofire 4.0 Upload MultipartFormData Header, it seems similar to my problem, the code is like this to upload Alamofire.upload(multipartFormData:{ multipartFormData in multipartFormData.append(unicornImageURL, withName: "unicorn") multipartFormData.append(rainbowImageURL, withName: "rainbow")}, usingThreshold