Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32159118
blob-service-upload.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
blob-service-upload.js
View Options
// @flow
import
*
as
FileSystem
from
'expo-file-system'
;
import
{
Platform
}
from
'react-native'
;
import
{
pathFromURI
}
from
'lib/media/file-utils.js'
;
import
type
{
BlobServiceUploadHandler
}
from
'lib/utils/blob-service-upload.js'
;
import
{
getMessageForException
}
from
'lib/utils/errors.js'
;
const
blobServiceUploadHandler
:
BlobServiceUploadHandler
=
async
(
url
,
method
,
input
,
options
,
)
=>
{
if
(
input
.
blobInput
.
type
!==
'uri'
)
{
throw
new
Error
(
'Wrong blob data type'
);
}
let
path
=
input
.
blobInput
.
uri
;
if
(
Platform
.
OS
===
'android'
)
{
const
resolvedPath
=
pathFromURI
(
path
);
if
(
resolvedPath
)
{
path
=
resolvedPath
;
}
}
const
uploadTask
=
FileSystem
.
createUploadTask
(
url
,
path
,
{
uploadType
:
FileSystem
.
FileSystemUploadType
.
MULTIPART
,
fieldName
:
'blob_data'
,
httpMethod
:
method
,
parameters
:
{
blob_hash
:
input
.
blobHash
},
},
uploadProgress
=>
{
if
(
options
?
.
onProgress
)
{
const
{
totalByteSent
,
totalBytesExpectedToSend
}
=
uploadProgress
;
options
.
onProgress
(
totalByteSent
/
totalBytesExpectedToSend
);
}
},
);
if
(
options
?
.
abortHandler
)
{
options
.
abortHandler
(()
=>
uploadTask
.
cancelAsync
());
}
try
{
await
uploadTask
.
uploadAsync
();
}
catch
(
e
)
{
throw
new
Error
(
`Failed to upload blob:
${
getMessageForException
(
e
)
??
'unknown error'
}
`
,
);
}
};
export
default
blobServiceUploadHandler
;
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sun, Dec 7, 4:26 PM (23 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5839567
Default Alt Text
blob-service-upload.js (1 KB)
Attached To
Mode
rCOMM Comm
Attached
Detach File
Event Timeline
Log In to Comment