Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/com/citrix/sharefile/api/https/upload/SFUploadRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ protected void runInThisThread() throws SFSDKException
}
abortIfCancelledRequested();

uploadUsingSingleHTTPPost();
if(mUploadSpecification.getMethod() != null && mUploadSpecification.getMethod().equals(SFUploadMethod.Streamed)){
upload();
}
else{
uploadUsingSingleHTTPPost();
}

abortIfCancelledRequested();
}
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/com/citrix/sharefile/api/https/upload/UploadHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down