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

uploadFile error 4.0.15 #3303

Closed
timershu opened this issue Jan 5, 2015 · 17 comments
Closed

uploadFile error 4.0.15 #3303

timershu opened this issue Jan 5, 2015 · 17 comments
Labels
Milestone

Comments

@timershu
Copy link

timershu commented Jan 5, 2015

Some file upload will be in error, some not
netty-file

public static boolean uploadFile(Bootstrap b,final File file,String host,int port) throws Exception {
HttpDataFactory factory = new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE);
if (!file.canRead()) {
throw new FileNotFoundException(file.getAbsolutePath()+"/"+file.getName());
}
URI uriFile = new URI("/formpost/zhenai" );
// Start the connection attempt.
final ChannelFuture cf = b.connect(new InetSocketAddress(host, port));
// Connection established successfully
// Wait until the connection attempt succeeds or fails.
Channel channel = cf.sync().channel();

    System.out.println("uriFile.toASCIIString()=="+uriFile.toASCIIString());
    // Prepare the HTTP request.
    HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uriFile.toASCIIString());

    // Use the PostBody encoder
    HttpPostRequestEncoder bodyRequestEncoder =
            new HttpPostRequestEncoder(factory, request, true); // true => multipart


    // add Form attribute
    bodyRequestEncoder.addBodyFileUpload("file", file, "application/x-zip-compressed", false);
    // finalize request
    try {
        request = bodyRequestEncoder.finalizeRequest();
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    // send request
    channel.write(request);
    // test if request was chunked and if so, finish the write
    if (bodyRequestEncoder.isChunked()) {
        ChannelFuture cFuture=channel.writeAndFlush(bodyRequestEncoder);
    } else {
        channel.flush();
    }
    // Now no more use of file representation (and list of HttpData)
    bodyRequestEncoder.cleanFiles();
    // Wait for the server to close the connection.
    channel.closeFuture().sync();
    //callback.call(true);
    return true;
}
@timershu timershu changed the title uploadFile error uploadFile error 4.0.15 Jan 5, 2015
@normanmaurer
Copy link
Member

@timershu please upgrade to 4.0.25.Final and try again. I think this was fixed before. If this is still an issue re-open.

@timershu
Copy link
Author

timershu commented Jan 5, 2015

There is an exception, some file upload, but the contents of the documents not upload to the server

@timershu
Copy link
Author

timershu commented Jan 5, 2015

netty01

@timershu
Copy link
Author

timershu commented Jan 7, 2015

@normanmaurer 4.0.25.Final Change package, bug still exists, the abnormal information is as follows。
netty02
Need me to put the file information to you

@normanmaurer normanmaurer added this to the 4.0.26.Final milestone Jan 7, 2015
@normanmaurer
Copy link
Member

@timershu we will have a look.... /cc @trustin

@normanmaurer
Copy link
Member

@timershu I think it's because you call cleanFiles() before the actual response may be written.

Use this:

// test if request was chunked and if so, finish the write
        if (bodyRequestEncoder.isChunked()) {
            ChannelFuture cFuture=channel.writeAndFlush(bodyRequestEncoder);
            cFuture.addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    // Now no more use of file representation (and list of HttpData)
                    bodyRequestEncoder.cleanFiles();
                }
            });
        } else {
            channel.flush();
            bodyRequestEncoder.cleanFiles();
        }

@normanmaurer
Copy link
Member

@timershu I don't understand... Can you explain what you try to say ?

@timershu
Copy link
Author

timershu commented Jan 7, 2015

@normanmaurer we decide not to adopt this project because of its instability

@timershu
Copy link
Author

timershu commented Jan 7, 2015

@normanmaurer In the day with 1000 files to be uploaded, occasionally only individual file upload failed

@normanmaurer
Copy link
Member

@timershu I still not get your point... the exception you posted here is because you call cleanFiles() to early . That will be fixed by my change.

@timershu
Copy link
Author

timershu commented Jan 7, 2015

@normanmaurer I would like to participate in this project, but the leaders feel that is not too stable, you need a change of plan. This random bug is how to produce? To provide under the relevant design data?

@timershu
Copy link
Author

timershu commented Jan 7, 2015

@normanmaurer I am in accordance with you provided inside the demo to write

@daschl
Copy link
Member

daschl commented Jan 7, 2015

@timershu did you apply the code suggested by @normanmaurer? You are using the code wrong it seems.

@timershu
Copy link
Author

timershu commented Jan 8, 2015

@normanmaurer
netty03
netty04

@timershu
Copy link
Author

timershu commented Jan 8, 2015

@normanmaurer @daschl This problem is whether the individual files, file reason?

@timershu
Copy link
Author

timershu commented Jan 8, 2015

netty05

@cleverpig
Copy link

mark~we have fixed in 4.0.26?

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

No branches or pull requests

4 participants