-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uploaded file has 0 B size #1645
Comments
Maybe this will help - content-length: 0
|
just for the record, this doesn't prove anything unless I can run code locally and see for myself that it works :) but thanks for the cURL command. it just makes sure that we are dealing with a normal multipart and the field-name is we are going to try to be constructive here and we can turn this thread into a definitive resource for troubleshooting karate file-upload. we will create a server that handles a curl command to upload a file and "prove" it works. we'll also print as much diagnostic information possible. and then - in theory, if you can point your existing test to this mock server, you should be able to spot what your broken test is doing differently. so here goes ! P.S. also note that https://httpbin.org can be used to quickly check what the structure of the multipart request being sent is: https://stackoverflow.com/a/78547136/143475 step 0make sure java is installed and in your step 1download the latest karate binary from the releases page, right now it is step 2rename it to step 3create the mock: here it is below: Feature:
Scenario: pathMatches('/upload')
* print 'method:', requestMethod
* print 'headers:', requestHeaders
* print 'requestParts:', requestParts
* def file = requestParts['file'][0]
* def length = file.value.length
* print 'bytes received:', length
* def response = { bytes: '#(length)' } step 4we need a file to upload. so have a so this is what things should look like: step 5start the server ! you can add
you should see the server start on the console. since this terminal is running it will be "blocked", so for the next step you need to open a new one, and you may want to use the same folder for convenience step 6fire your curl command in a new terminal ! note how I am using your curl command "as is" without changes to "prove" things. use the full, absolute path of the file if needed. here please refer to the cURL documentation if in doubt.
and you should see this result ! which confirms that the file went to server, bytes and all. this is what the last line of
what you see on the server log also will be quite informative:
step 7see if a karate test has the same effect. here is Feature:
Scenario:
* url 'http://localhost:8080/upload'
* multipart file file = { read: 'test.xlsx', filename: 'my-file.xlsx', contentType: 'text/csv' }
* method post
* status 200
* match response == { bytes: '#number' } step 8run the karate test !
voila ! so now point your test to happy testing :) |
Thanks @ptrthomas for providing above instruction. I followed it and I got the same result as you. Seems like locally the upload works. |
I'm pretty sure you are reading the file wrong which others also tried telling you on stack overflow. but yes, you will have to live with 0.9.X or perhaps its time to switch to P0stman :) closing this ticket |
What do you mean that "I'm reading the file wrong"? I do it the same way in 1.X.X like in 0.9.6. PS. A note about Postman is not necessary here. |
@intest it is possible we fixed bugs in the file-reading that changed behavior - and you were depending on the buggy behavior :) ok you can use JMeter then |
OK, so how my Karate request should look like to make it work? PS. I don't get your comments about p..man or jmeter.. I never said that they are better tools or whatever. I really like Karate and I just switched to it from jmeter. What is your point while commenting like that? I like your tool and I would expect that you want people to use your tool. Only that I mentioned those 2 tools doesn't mean I consider them as better than Karate. I just wanted to mention them to clarify that it was not an issue with server or anything else. |
@intest I have to see EXACTLY how your project is set up to determine that - which apparently is not possible ! and a working example is provided above, take it or leave it. I'm locking this thread now. questions can be asked on stack overflow. |
Hello! It helped a lot! Thank yo so much, Peter! |
@ptrthomas It's a continuation of this issue #1605, you asked for a prove that it works for me with P*stman. So the cURL is:
And here is the file on S3:
![xlsx_from_postman](https://user-images.githubusercontent.com/69465676/122238408-65174a80-cec0-11eb-99ac-5e3364cae5fd.PNG)
As you can see - it works. And it worked the same with K0.9.6.
And I would be grateful if you didn't offend me ;) writing "(...) it does sound like tools like P0stman are simpler and possibly a better fit for you". I actually migrated hundrets of tests from JMeter to Karate and it's a cool tool, but sometimes I come across such traps and I think is quite normal to ask for help or raise a bug :) (I use P*stman from time to time just for debugging)
Peace! :)
The text was updated successfully, but these errors were encountered: