Skip to content
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

post file method Invalid binary file sent #673

Open
rajneshrathor opened this issue Sep 20, 2024 · 4 comments
Open

post file method Invalid binary file sent #673

rajneshrathor opened this issue Sep 20, 2024 · 4 comments

Comments

@rajneshrathor
Copy link

rajneshrathor commented Sep 20, 2024

## Issue: Invalid Blob Data Received via FitNesse `post file` Method

### Problem Statement:
I need to send blob data using the `post file` method in FitNesse. However, an invalid file is being received on the server-side. Below is the FitNesse code snippet:

!2 Change ND20002 status to Conceptakte ontavegan
-|script |
|push fixture |
|start |json http test |
|set value|!-Bearer -!$accessToken |for header|Authorization |
|set value|application/octet-stream |for header|Content-Type |
|post file|http://files/nobilex/testaktedoc.zip|to |${APP_URL}/external-api/nds/v1.0/ndRequest/uploadConceptAkte/20002|
|check |response status |200 |
|show |response time |
|show |response |
|pop fixture |


Below is  the API code :

```kotlin
@Secured(ServiceAccountRoleConstants.NDS)
@PostMapping("/uploadConceptAkte/{ndId}", consumes = [MediaType.APPLICATION_OCTET_STREAM_VALUE], produces = [MediaType.APPLICATION_JSON_VALUE])
fun uploadConceptAkte(@PathVariable ndId: String, @RequestBody zip: ByteArray, request: HttpServletRequest) {
    println("Zip: ${zip.size}")
    File("/home/Desktop/ND.zip").writeBytes(zip)
}

Current Behavior:

  • The file is valid and is correctly saved when I use Postman.
  • However, when using the FitNesse API call, an invalid file is saved, and I cannot open the uploaded ZIP file. also file size gets increased

Metadata Screenshots:

  • FitNesse metadata:
    fitnesse metadata

  • Postman metadata:
    postman metadata

Postman Curl request -

curl --location 'API-URL'
--header 'Content-Type: application/octet-stream'
--header 'Accept: application/json'
--header 'Authorization: Bearer eyJhbG....'
--data '@/home/rajnesh/angular/project1/fitnesse/wiki/FitNesseRoot/files/test-akte-doc.zip'

Request for Help:

Any insights on why the file is valid via Postman but invalid via FitNesse would be appreciated.

Thanks in advance!


This format ensures that your code and issue are clearly structured, with the right emphasis on your problem and the necessary context for others to help debug.
@rajneshrathor rajneshrathor changed the title Invalid binary file sent using post file method post file method Invalid binary file sent Sep 20, 2024
@fhoeben
Copy link
Owner

fhoeben commented Sep 22, 2024

No immediate reason/solution comes to mind. I do notice however that you seem to be sending 2 different files in the curl command (/files/test-akte-doc.zip) and in the FitNesse page (/files/nobilex/testaktedoc.zip). I don't know whether that is meaningful.

Does the error only occur when you send zip files, or is the received content also corrupted/different when sending an image or text file?

Can you enable more logging on the server side to see exactly what is received (maybe using a mock server). It would be good to see the exact differences.

@rathodrajnesh
Copy link

rathodrajnesh commented Sep 23, 2024

Hi @fhoeben,

Both files are the same; I just simplified the file name for clarity. I also tried sending a PNG file, but it was also received as corrupted.

Interestingly, when sending a .txt file, I noticed extra content in the file. Please find attached the example of the .txt file received with additional content. Selected txt is original content.

Looking forward to your insights.

Thanks!

@rajneshrathor
Copy link
Author

I can see same issue here also #510 (comment) getting same additional things while with postman only original data receievedI noticed that this issue seems to be similar to the one mentioned here: Issue #510. I'm experiencing the same problem where additional content is being added to the file when using FitNesse. However, when I use Postman, only the original data is received without any extra content.

@fhoeben
Copy link
Owner

fhoeben commented Sep 24, 2024

@rajneshrathor sorry but that doesn't help exactly as in that issue I also asked for more information and that was never provided.

The screenshot you provide is that the content of the file as your server created based on the upload? It looks like the server is not accepting a multi part file upload but is just saving the full body as file content. Are you doing a multipart form upload from Postman, or just posting the file's content?

Can you add some logging at the server level, so we can see the raw http data exchanged?

Another thing you could try to do is have both the fixture and Postman send the file to nc which will output the full content received.

For instance locally (on my Mac) I started a server listening on port 8001 from a terminal using nc -l localhost 8001, when I then post a file using HttpTest:

|script   |http test           |
|post file|$createdFile|to|http://localhost:8001/|

I get output like:

POST / HTTP/1.1
Content-Length: 271
Content-Type: multipart/form-data; boundary=QeIStjzo_n9FvR8uVVfSpfEeQjF8hd67eg1xC-
Host: localhost:8001
Connection: Keep-Alive
User-Agent: nl.hsac.fitnesse.fixture.util.HttpClient

--QeIStjzo_n9FvR8uVVfSpfEeQjF8hd67eg1xC-
Content-Disposition: form-data; name="file"; filename="upload.txt"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

This is a file to test the file upload
--QeIStjzo_n9FvR8uVVfSpfEeQjF8hd67eg1xC---

(I then have to interrupt the server using Ctrl+C)

Could you do the same using both HttpTest and Postman and share both outputs? That might help understand the difference?

As an example here is a multi part upload I did using Insomnia
image

Which created the following output from nc:

POST / HTTP/1.1
Host: localhost:8001
Content-Type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY
User-Agent: insomnia/8.3.0
Accept: */*
Content-Length: 184

--X-INSOMNIA-BOUNDARY
Content-Disposition: form-data; name="file"; filename="upload.txt"
Content-Type: text/plain

This is a file to test the file upload
--X-INSOMNIA-BOUNDARY--

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants