itinance / itinance/react-native-fs

Getting [Error: Socket is closed] when trying to upload files to S3 signed URL

Open
#955 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Hi,

When trying to S3 signed URLs, I get `[Error: Socket is closed]`.

This is the code:

```js

const {originalFilepath, path, size} = await RNFS.stat(fileUri);
const filepath = path || originalFilepath || fileUri;

const files: UploadFileItem[] = [
{
name: 'file',
filename: 'video',
filepath,
filetype: 'video/mp4',
},
];

const toUrl = getKey('url');
const fields = {
Key: getKey('key'),
Bucket: getKey('bucket'),
Policy: getKey('Policy'),
'X-Amz-Algorithm': getKey('X-Amz-Algorithm'),
'X-Amz-Credential': getKey('X-Amz-Credential'),
'X-Amz-Date': getKey('X-Amz-Date'),
'X-Amz-Security-Token': getKey('X-Amz-Security-Token'),
'X-Amz-Signature': getKey('X-Amz-Signature'),
};

const response = await RNFS.uploadFiles({
toUrl: 'https://s3.us-west-1.amazonaws.com/localjob-development',
files,
method: 'POST',
headers: {
Accept: 'application/json',
},
fields,
begin: uploadBegin,
progress: uploadProgress,
}).promise;

```

I see the error in console:
```
backend.js:32 Error: Socket is closed
at Object.promiseMethodWrapper [as uploadFiles] (NativeModules.js:103)
at Object.uploadFiles (FS.common.js:594)
at uploadVideo$ (useUploadVideo.tsx:98)
at tryCatch (runtime.js:63)
at Generator.invoke [as _invoke] (runtime.js:293)
at Generator.next (runtime.js:118)
at tryCatch (runtime.js:63)
at invoke (runtime.js:154)
at runtime.js:164
at tryCallOne (core.js:37) "{"nativeStackAndroid":[],"userInfo":null,"message":"Socket is closed","code":"EUNSPECIFIED"}"
n @ backend.js:32
registerWarning @ LogBox.js:117
warnImpl @ LogBox.js:63
console.warn @ LogBox.js:36
uploadVideo$ @ useUploadVideo.tsx:117
tryCatch @ runtime.js:63
invoke @ runtime.js:293
(anonymous) @ runtime.js:118
tryCatch @ runtime.js:63
invoke @ runtime.js:154
(anonymous) @ runtime.js:166
tryCallOne @ core.js:37
(anonymous) @ core.js:123
(anonymous) @ JSTimers.js:274
_callTimer @ JSTimers.js:130
_callImmediatesPass @ JSTimers.js:181
callImmediates @ JSTimers.js:441
__callImmediates @ MessageQueue.js:387
(anonymous) @ MessageQueue.js:135
__guard @ MessageQueue.js:364
flushedQueue @ MessageQueue.js:134
invokeCallbackAndReturnFlushedQueue @ MessageQueue.js:130
(anonymous) @ debuggerWorker.cff11639.js:4
```

It would be great if I could get a more meaningful error.

My guess is the fields' order. Amazon S3 cares about the order of fields sent. I am worried the order is not preserved when serialising and crafting the request. But I am not sure about this as I get no meaningful error.

Thanks

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.