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

Response Headers while downloading files #18

Closed
wants to merge 4 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.drpogodin.reactnativefs;
import java.util.Map;

public class DownloadResult {
public int statusCode;
public long bytesWritten;
public Exception exception;
public Map<String, String> headers;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.net.HttpURLConnection;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.Map;
import java.util.HashMap;

import android.util.Log;

Expand Down Expand Up @@ -142,6 +144,7 @@ private void download(DownloadParams param, DownloadResult res) throws Exception

output.flush();
res.bytesWritten = total;
res.headers = headersFlat;
}
res.statusCode = statusCode;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,14 @@ public void onTaskCompleted(DownloadResult res) {
infoMap.putInt("jobId", jobId);
infoMap.putInt("statusCode", res.statusCode);
infoMap.putDouble("bytesWritten", (double)res.bytesWritten);
if(res.statusCode >= 200 && res.statusCode < 300){
// Create a WritableMap for the headers
WritableMap headersMap = Arguments.createMap();
for (Map.Entry<String, String> entry : res.headers.entrySet()) {
headersMap.putString(entry.getKey(), entry.getValue());
}
infoMap.putMap("headers", headersMap);
}

promise.resolve(infoMap);
} else {
Expand Down
Loading