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

Support unicode encode request when uploading on Android #1088

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 6 additions & 6 deletions android/src/main/java/com/rnfs/Uploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void upload(UploadParams params, UploadResult result) throws Exception {
while (fieldsIterator.hasNextKey()) {
String key = fieldsIterator.nextKey();
String value = params.fields.getString(key);
metaData += twoHyphens + boundary + crlf + "Content-Disposition: form-data; name=\"" + key + "\"" + crlf + crlf + value +crlf;
metaData += twoHyphens + boundary + crlf + "Content-Disposition: form-data; name=\"" + key + "\"" + crlf + crlf + value + crlf;
}
stringData += metaData;
fileHeader = new String[files.length];
Expand Down Expand Up @@ -122,7 +122,7 @@ private void upload(UploadParams params, UploadResult result) throws Exception {
}
if (!binaryStreamOnly) {
long requestLength = totalFileLength;
requestLength += stringData.length() + files.length * crlf.length();
requestLength += stringData.getBytes("UTF-8").length + files.length * crlf.getBytes("UTF-8").length;
connection.setRequestProperty("Content-length", "" +(int) requestLength);
connection.setFixedLengthStreamingMode((int)requestLength);
}
Expand All @@ -132,14 +132,14 @@ private void upload(UploadParams params, UploadResult result) throws Exception {
WritableByteChannel requestChannel = Channels.newChannel(request);

if (!binaryStreamOnly) {
request.writeBytes(metaData);
request.write(metaData.getBytes("UTF-8"));
}

byteSentTotal = 0;

for (ReadableMap map : params.files) {
if (!binaryStreamOnly) {
request.writeBytes(fileHeader[fileCount]);
request.write(fileHeader[fileCount].getBytes("UTF-8"));
}

File file = new File(map.getString("filepath"));
Expand All @@ -162,15 +162,15 @@ private void upload(UploadParams params, UploadResult result) throws Exception {
}

if (!binaryStreamOnly) {
request.writeBytes(crlf);
request.write(crlf.getBytes("UTF-8"));
}

fileCount++;
fileStream.close();
}

if (!binaryStreamOnly) {
request.writeBytes(tail);
request.write(tail.getBytes("UTF-8"));
}
request.flush();
request.close();
Expand Down