-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fetch API
config(options:RNFetchBlobConfig):fetch
0.5.0
Config API was introduced in v0.5.0
which provides some options for the fetch
task.
fetch(method, url, headers, body):Promise<RNFetchBlobResponse>
legacy
Send a HTTP request uses given headers and body, and return a Promise.
HTTP request method, can be one of get
, post
, delete
, and put
, case-insensitive.
HTTP request destination url.
Headers of HTTP request, value of headers should be stringified
, if you're uploading binary files, content-type should be application/octet-stream
or multipart/form-data
(see examples above).
Body of the HTTP request, body can either be a BASE64 string, or an array contains object elements, each element have 2 required property name
, and data
, and 1 optional property filename
, once filename
is set, content in data
property will be consider as BASE64 string that will be converted into byte array later.
When body is a base64 string , this string will be converted into byte array in native code, and the request body will be sent as application/octet-stream
.
fetch(...).progress(eventListener):Promise<RNFetchBlobResponse>
0.4.2
Register on progress event handler for a fetch request.
A function that triggers when there's data received/sent, first argument is the number of sent/received bytes, and second argument is expected total bytes number.
Simply prepend RNFetchBlob-file://
to a path, this make the file path becomes recognizable to native fetch
method.
Session API helps managing cached files, the following code, will try to return an existing session object with the given name
, if it does not exist, create one.
RNFetchBlob.session('mysession')
see Sessions API for usage.
0.4.2
A helper class simply uses base-64 for decode and encode BASE64 data.
RNFetchBlob.base64.encode(data)
RNFetchBlob.base64.decode(data)