[Interest] QNetworkAccessManager put uploads contents twice

Thiago Macieira thiago.macieira at intel.com
Tue Dec 1 07:09:09 CET 2015


On Tuesday 01 December 2015 11:30:32 ashish dabhade wrote:
> To avoid that I also tested it by removing the authenticationRequired and
> passing username and password in the url as per basic auth specs. For eg.
> QUrl( "http://user:password@192.168.1.157/webdav/Media/somefile.mp4" ).
> This too resulted the same behavior.

QNetworkAccessManager needs to know which authentication method to use. It can 
only get that information after trying the server first.

Try this: get, post or put something else in the same server, so you're 
authenticated. I'm not sure if this works, but we can call this a missing 
feature if it doesn't.

> Also suppose the file is of large size say for eg. 300 Mb. wouldn't it be
> unnecessary to upload so much data twice ?

It's a limitation of the HTTP protocol. QNAM can use the

	Expects: 100

header and the server MAY reply with an error message before the end of the 
upload. But it's not a guarantee that it will, so QNAM has to try and upload 
everything.

If you don't like this, try using a different protocol.

> I tested the same scenario with the now deprecated **QHttp** class and to
> the surprise it uploaded the contents just once.

If you don't try something first, QHttp will use Basic authentication, which is 
not secure (the password is sent in the clear). QNAM doesn't allow that: you 
need to get the authentication mechanisms first so that it will try the most 
secure option.

> So if the above scenario is due to the design what would be the best way to
> handle it ? For smaller files it is fine. I wanted to show the progress bar
> for uploading which now fills up twice :)

See above for two alternatives.
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list