Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] send file using HTTP/3

Hi,

On Wed, Oct 19, 2022 at 12:20 PM Mateusz K. <matkoz1988@xxxxxxxxx> wrote:
>
> Hello,
> Im further trying to learn programming jetty and http/3 in general. My current task is to send a 10MB file using PUT request. Pardon my lack of expertise in what i will try to describe, im still learning java :-).

Since you pasted much code, next time open an issue, where the code
formatting can be retained, as in emails it's impossible to read the
code.

> So far i tried 2 approaches, first which failed instantly, was:

[snip]

It is ok to read the 10 MiB all at once and send it in one call to
Stream.data() -- like you are doing in the first approach.
However, on the receiving side, you will likely receive multiple
DataFrames that when they are re-assembled will produce the original
whole content.

If I read your code correctly, on the server side you open a file,
save a chunk of bytes, then close the file, so the file will
eventually only have the last chunk in it.
You have to open the file in append mode, or keep it open until you
see the last DataFrame.

In your second approach, it is ok to read the source bytes in chunks,
but don't rely on available().
You should read a source chunk and send it as a non-last DataFrame,
until you read -1.
When you read -1, you send an empty, last, DataFrame.

-- 
Simone Bordet
---
Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless.   Victoria Livschitz


Back to the top