diff --git a/src/com/citrix/sharefile/api/https/upload/SFUploadRunnable.java b/src/com/citrix/sharefile/api/https/upload/SFUploadRunnable.java index fdf6879..4c71413 100644 --- a/src/com/citrix/sharefile/api/https/upload/SFUploadRunnable.java +++ b/src/com/citrix/sharefile/api/https/upload/SFUploadRunnable.java @@ -174,7 +174,12 @@ protected void runInThisThread() throws SFSDKException } abortIfCancelledRequested(); - uploadUsingSingleHTTPPost(); + if(mUploadSpecification.getMethod() != null && mUploadSpecification.getMethod().equals(SFUploadMethod.Streamed)){ + upload(); + } + else{ + uploadUsingSingleHTTPPost(); + } abortIfCancelledRequested(); } @@ -403,19 +408,24 @@ private long uploadChunk(byte[] fileChunk,int chunkLength,long index,boolean isL md.update(fileChunk, 0, chunkLength); //you need the RAW param or you'll have to do HTTP multi-part post... - String append = UploadHelper.getAppendParams(mDestinationFileName, mDetails, mTotalBytes,isLast?1:0, isLast, md5ToString(md),index, previousChunkTotal); + String append = UploadHelper.getAppendParams(mDetails, isLast?1:0, isLast, md5ToString(md), index, previousChunkTotal, chunkLength); final URL finalURL = new URL( mUploadSpecification.getChunkUri() + append); conn = UploadHelper.getChunkUploadConnection(finalURL.toString(), mApiClient, mUsername, mPassword, mCookieManager, chunkLength); + + if(isLast){ + conn.setReadTimeout(10*60*1000); + } + SFConnectionManager.connect(conn); //small buffer between the chunk and the stream so we can interrupt and kill task quickly - final byte[] buffer = new byte[1024]; + final byte[] buffer = new byte[8192]; final ByteArrayInputStream in = new ByteArrayInputStream(fileChunk,0,chunkLength); int currentBytesRead; OutputStream poster = new DataOutputStream(conn.getOutputStream()); - while((currentBytesRead = in.read(buffer,0,1024)) >0) + while((currentBytesRead = in.read(buffer,0, 8192)) > 0) { poster.write(buffer,0,currentBytesRead); bytesUploaded+=(long)currentBytesRead; diff --git a/src/com/citrix/sharefile/api/https/upload/UploadHelper.java b/src/com/citrix/sharefile/api/https/upload/UploadHelper.java index d381556..8feedd6 100644 --- a/src/com/citrix/sharefile/api/https/upload/UploadHelper.java +++ b/src/com/citrix/sharefile/api/https/upload/UploadHelper.java @@ -22,7 +22,7 @@ public class UploadHelper { private static final String TAG = "UploadHelper"; - public static String getAppendParams(String filename, String mDetails, long fileSize,int finish,boolean isbatchLast,String hash,long index, long previousChunkTotal) + public static String getAppendParams(String mDetails, int finish, boolean isbatchLast, String hash, long index, long previousChunkTotal, int chunkLength) { Logger.d(TAG, "ResumeSupp: Uploading chunk: index" + index + " offset: " + previousChunkTotal); StringBuilder sb = new StringBuilder(); @@ -32,10 +32,10 @@ public static String getAppendParams(String filename, String mDetails, long file if(isbatchLast) { sb.append("&isbatchlast=true"); + sb.append("&filesize=" + (previousChunkTotal + chunkLength)); } sb.append("&fmt=json"); sb.append("&hash="+hash); - sb.append("&filesize="+fileSize); sb.append("&index="+index); sb.append("&byteOffset="+previousChunkTotal); @@ -83,6 +83,7 @@ public static HttpURLConnection getChunkUploadConnection(String finalURL, SFApiC SFHttpsCaller.addAuthenticationHeader(conn, mApiClient.getOAuthToken(), mUsername,mPassword,mCookieManager); conn.setUseCaches(false); + conn.setReadTimeout(30*1000); conn.setRequestProperty(SFKeywords.CONTENT_TYPE, SFKeywords.APPLICATION_OCTET_STREAM); conn.setRequestProperty(SFKeywords.CONTENT_LENGTH, ""+chunkLength); conn.setFixedLengthStreamingMode(chunkLength);