use content-type in http slot request and stick with during upload
This commit is contained in:
parent
f9dec7cf86
commit
5529337da3
|
@ -254,12 +254,15 @@ public class IqGenerator extends AbstractGenerator {
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket requestHttpUploadSlot(Jid host, DownloadableFile file) {
|
public IqPacket requestHttpUploadSlot(Jid host, DownloadableFile file, String mime) {
|
||||||
IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
||||||
packet.setTo(host);
|
packet.setTo(host);
|
||||||
Element request = packet.addChild("request",Xmlns.HTTP_UPLOAD);
|
Element request = packet.addChild("request",Xmlns.HTTP_UPLOAD);
|
||||||
request.addChild("filename").setContent(file.getName());
|
request.addChild("filename").setContent(file.getName());
|
||||||
request.addChild("size").setContent(String.valueOf(file.getExpectedSize()));
|
request.addChild("size").setContent(String.valueOf(file.getExpectedSize()));
|
||||||
|
if (mime != null) {
|
||||||
|
request.addChild("content-type", mime);
|
||||||
|
}
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ public class HttpUploadConnection implements Transferable {
|
||||||
private Account account;
|
private Account account;
|
||||||
private DownloadableFile file;
|
private DownloadableFile file;
|
||||||
private Message message;
|
private Message message;
|
||||||
|
private String mime;
|
||||||
private URL mGetUrl;
|
private URL mGetUrl;
|
||||||
private URL mPutUrl;
|
private URL mPutUrl;
|
||||||
|
|
||||||
|
@ -93,6 +94,7 @@ public class HttpUploadConnection implements Transferable {
|
||||||
mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
|
mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
|
||||||
this.account = message.getConversation().getAccount();
|
this.account = message.getConversation().getAccount();
|
||||||
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
|
this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
|
||||||
|
this.mime = this.file.getMimeType();
|
||||||
this.delayed = delay;
|
this.delayed = delay;
|
||||||
if (Config.ENCRYPT_ON_HTTP_UPLOADED
|
if (Config.ENCRYPT_ON_HTTP_UPLOADED
|
||||||
|| message.getEncryption() == Message.ENCRYPTION_AXOLOTL
|
|| message.getEncryption() == Message.ENCRYPTION_AXOLOTL
|
||||||
|
@ -105,7 +107,7 @@ public class HttpUploadConnection implements Transferable {
|
||||||
this.file.setExpectedSize(pair.second);
|
this.file.setExpectedSize(pair.second);
|
||||||
this.mFileInputStream = pair.first;
|
this.mFileInputStream = pair.first;
|
||||||
Jid host = account.getXmppConnection().findDiscoItemByFeature(Xmlns.HTTP_UPLOAD);
|
Jid host = account.getXmppConnection().findDiscoItemByFeature(Xmlns.HTTP_UPLOAD);
|
||||||
IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host,file);
|
IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host,file,mime);
|
||||||
mXmppConnectionService.sendIqPacket(account, request, new OnIqPacketReceived() {
|
mXmppConnectionService.sendIqPacket(account, request, new OnIqPacketReceived() {
|
||||||
@Override
|
@Override
|
||||||
public void onIqPacketReceived(Account account, IqPacket packet) {
|
public void onIqPacketReceived(Account account, IqPacket packet) {
|
||||||
|
@ -149,6 +151,7 @@ public class HttpUploadConnection implements Transferable {
|
||||||
}
|
}
|
||||||
connection.setRequestMethod("PUT");
|
connection.setRequestMethod("PUT");
|
||||||
connection.setFixedLengthStreamingMode((int) file.getExpectedSize());
|
connection.setFixedLengthStreamingMode((int) file.getExpectedSize());
|
||||||
|
connection.setRequestProperty("Content-Type", mime == null ? "application/octet-stream" : mime);
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
connection.connect();
|
connection.connect();
|
||||||
os = connection.getOutputStream();
|
os = connection.getOutputStream();
|
||||||
|
|
Loading…
Reference in a new issue