Git Product home page Git Product logo

react-native-fetch-blob's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-fetch-blob's Issues

[IOS] NSURLSession support

When app turned into background, HTTP connections will be interrupt. This would be a problem when transmitting large data.

[Android] undefined is not an object (evaluating 'RNFetchBlob.DocumentDir')

Hello!

This error appears at start launch in the simulator/device.

In my example I'm trying implement this part of code, how we can avoid this issue?

Thank you in advance.

componentDidMount() { RNFetchBlob .config({ // add this option that makes response data to be stored as a file, // this is much more performant. fileCache : true, }) .fetch('GET', 'https://homepages.cae.wisc.edu/~ece533/images/mountain.png') .then((res) => { // the temp file path console.log('The file saved to ', res.path('/')) }) requestPermission("android.permission.ACCESS_FINE_LOCATION").then((result) => { console.log("Granted!", result);// now you can set the listenner to watch the user geo location }, (result) => { console.log("Not Granted!"); console.log(result); });

[email protected]
[email protected]
[email protected]
[email protected]

img1
img2

go into error except in chrome debugging

I use fetch to post a base64 image data and always go into error in debug or release. when i open debug js, it success. what's wrong. is it anything i have to setting?

Self signed certificates

Hi. I tried to use your library and get a problem if the site uses self signed certificate. Do you have any solution for that?

[Android] Download Manager support

Download Manager provides better UX for Android users, we should add support for this.

Also, download file using download manager can avoid problems when app is in suspended.

  • Download notification
  • Download using download manager API
  • Test cases

.progress() not working

Are you sure this works? As in my case it doesn't seem to enter in the functions and jumps directly to .then()/.catch(). It waited for the file to upload but never executed anything inside the .progress().
Or may be you could provide an example(point me to it) on how to use it.
Btw, thanks, I'm new to RN and iOS, when nothing else seemed to work, rnfb worked well.
here:
trySendingImageToServer(url,base64ImageString,tryNum){
RNFetchBlob.fetch('POST',url,{
'Authorization' : 'Basic YWRtaW46MXEydzNlNHIlVA==',
},base64ImageString)
.progress((received,total)=>{
console.log('progress',received/total);
})
.then((resp)=>{
console.log("Response : ",resp.text());
})
.catch((err)=>{
console.log("Error : ",err);
if (tryNum>0){
this.trySendingImageToServer(url,base64ImageString,tryNum-1);
console.log("Trying again.. "+tryNum);
}
else{
console.log("Not trying anymore");
Alert.alert('Please check your connection');
}
});
}

Compatible to ES5

Refer to #58 , since the module uses ES6 style export, developers who uses require('react-native-fetch-blob') will not be able to use the module directly. Though they can still uses by using default property, but it would be better if the module can be used more easily.

Undefined error

Hi,

I want to use your package for fetching network images.
The images are protected by Basic Auth.

I would like to use them in an component, but keep getting following error on RNFetchBlob.fetch():

TypeError: Cannot read property 'fetchBlob' of undefined

I'm on RN ^0.22.2
i've installed rnpm and ran the rnpm link command

Any clue on what i'm missing here?

Library doesn't compile with project on IOS

I get the below error message when I try to compile my project in IOS. The project works fine on android. I have followed the steps as given in the installation section.
screen shot 2016-07-01 at 7 15 41 pm

Changes that slowed down download?

Hi guys,

I'm using this library to download a massive amount of separate files to disk (1k+ per load). It's a mapping application, and so this is necessary.

Since the latest version (I upgraded from 0.4.2 to 0.5.2) downloads have slowed down significantly. Any suggestions where I can look to fix this? It almost seems like the requests are now syncrhonous instead of asynchronous. Unable to perform multiple requests at the same time?

Thanks!

Seperate upload and download progress event

IOS supports both upload and download progress, but there's only one way to register progress event handler, this will cause unexpected progress event triggering on IOS.

  • implement android upload progress in 0.7.0

[Android] Switch to OKHttp

React-Native implements fetch API using OKHTTP, we should consider use it.

TODOs

  • Android content URI read problem
  • Multipart content length correctness
  • Documentation

v0.5.0 release preparation

v0.5.0 features are almost finished, before it release we still got something to do.

  • Documentation
  • More test cases
  • System directory API improvement
  • Memory and file cache release

Support for iOS assets-library:// files

It's unclear from the docs whether or not this library can be used to upload images from an iOS user's camera roll. The React Native camera roll API returns file URIs like, assets-library://asset/asset.JPG?id=1234-5678-ABCDE-3210&ext=JPG. Should I be able to use RNFetchBlob.wrap() on such a URI, like:

RNFetchBlob.fetch('POST', 'http://www.example.com/upload-form', {
    Authorization : "Bearer access-token",
    'Content-Type' : 'multipart/form-data',
  }, [
    // append field data from file path
    {
      name : 'avatar',
      filename : 'avatar.png',
      data: RNFetchBlob.wrap("assets-library://asset/asset.JPG?id=1234-5678-ABCDE-3210&ext=JPG")
    }
...

upload doesn't work

I'm getting the error:

sorry, the request failed. Please try again. {line: 381, column: 882, sourceURL: file: //index.android.bundle.

Not really sure what the error is all about but it seems I do not get this error when I enable chrome debugging. I tried creating a deploy version of the app in hopes that it would work but it didn't.

I'll come back later to update and provide more info.

New fs APIs make file concat and replace more efficient

Consider the following scenario

If we wish to concat two files or replace content of one file by another, we have to cache the file content in JS context and then write the data to destination.

const fs = RNFetchBlob.fs
fs.readFile(FILE_SRC, 'base64')
     .then((b64data) => fs.appendFile(FILE_DEST, b64data, 'base64'))
     .then(() => {  console.log(`concated ${FILE_SRC} to ${FILE_DEST}`) })

This seems not efficient especially when the file is big, that cache will likely consume up the available memory.

Therefore, I think we should make writeStream, writeFile, and appendFile accept a file path as their input, and then we can do as follow.

const fs = RNFetchBlob.fs
fs.appendFile(FILE_DEST, FILE_SRC, 'uri')
     .then(() => {  console.log(`concated ${FILE_SRC} to ${FILE_DEST}`) })
  • Add uri encoding type to writeFile
  • Add uri encoding type to appendFile
  • Test cases

HTTP request should be able to cancel and resume

Related to #37 , cancel mechanism will be added into 0.7.0.

resume can be achieved by simply using Range header, and appendFile function. That might be an inefficient way but we will improve that after #56 .

  • Android part (cancel request)
  • IOS part (cancel request)
  • test cases
  • documentation

[iOS] Can't build without ARC errors

RNFetchBlobNetwork.m:32:13: ARC forbids synthesizing a property of an Objective-C object with unspecified ownership or storage attribute
RNFetchBlobNetwork.m:35:13: ARC forbids synthesizing a property of an Objective-C object with unspecified ownership or storage attribute
RNFetchBlobNetwork.m:36:13: ARC forbids synthesizing a property of an Objective-C object with unspecified ownership or storage attribute
RNFetchBlobFS.h:18:28: Existing instance variable 'callback' for property 'callback' with unsafe_unretained attribute must be __unsafe_unretained

I'm using 0.5.3.
Is it because I've added the project manually rather then with rnpm and have missed some build flags?

Android runtime permissions

Hi,

Android 23 runs with runtime permissions, so if you want to write to the downloads folder for example you don't just state that in the manifest file, you also have to have a runtime check and confirmation from the user.

https://developer.android.com/training/permissions/requesting.html

I can't see that how this has been implemented in this module, if it hasn't due to being outside of scope / requirements then does anyone have any advice on how to apply this. Due to the nature of the module here I would think it would be very useful to add to the Read me.

Thanks

Network optimization (don't re-download if present in cache)

Hi @wkh237, awesome library, much needed in React Native.

My suggestion is:

  • if fileCache is set to true
  • when a fetch is issued, check if that url has already been downloaded
  • if it has, return the path
  • if it hasn't, request from the server as normal

Let me know if you will pursue such a change, in any case I'll take a look at the code and see if I can come up with something (at least on the Android side)

File cache management

In upcoming version v0.5.0, new APIs allow RN app access file system directly, is there a better solution to remove cached files than just manually calling unlink API ?

  • session API implementation

Move API document to wiki

The README.md has to much content, I think it would be better to leave recipes in README.md and move API references to wiki.

Allow setting custom Content-Type within multi-part forms

I had a case when working with an API where I needed to specifically set the Content-Type (from "application/octet-stream" to "image/jpeg". As a quick hack, I implemented it this way [on the feat_45 branch]:

diff --git a/src/ios/RNFetchBlobReqBuilder.m b/src/ios/RNFetchBlobReqBuilder.m
index df4c3d1..6b44b74 100644
--- a/src/ios/RNFetchBlobReqBuilder.m
+++ b/src/ios/RNFetchBlobReqBuilder.m
@@ -134,6 +134,7 @@
         {
             NSString * name = [field valueForKey:@"name"];
             NSString * content = [field valueForKey:@"data"];
+            NSString * contentType = [field valueForKey:@"type"];
             // field is a text field
             if([field valueForKey:@"filename"] == nil || content == [NSNull null]) {
                 [formData appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
@@ -155,7 +156,7 @@
                             NSString * filename = [field valueForKey:@"filename"];
                             [formData appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
                             [formData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", name, filename] dataUsingEncoding:NSUTF8StringEncoding]];
-                            [formData appendData:[[NSString stringWithFormat:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
+                            [formData appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", contentType] dataUsingEncoding:NSUTF8StringEncoding]];
                             [formData appendData:content];
                             [formData appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
                             i++;
@@ -174,7 +175,7 @@
                 NSString * filename = [field valueForKey:@"filename"];
                 [formData appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
                 [formData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", name, filename] dataUsingEncoding:NSUTF8StringEncoding]];
-                [formData appendData:[[NSString stringWithFormat:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
+                [formData appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", contentType] dataUsingEncoding:NSUTF8StringEncoding]];
                 [formData appendData:blobData];
                 [formData appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
             }

..and used it like this:

            RNFetchBlob.fetch('POST', url, {
                Authorization: `Bearer ${token}`,
                Accept: "application/json",
                "Content-Type": "multipart/form-data",
            }, [
                {
                    name: 'image',
                    filename: filename,
                    data: RNFetchBlob.wrap(asset.uri),
                    "type": 'image/jpeg',
                },
                {
                    name: "someOtherField",
                    data: JSON.stringify({foo: 1, bar: 2}),
                    "type": "application/json",
                },

I figured you might want to implement it different so that it's optional, and works on Android, so no PR currently :-)

Implement Blob and other polyfills

According to #37 advice from @vaibhawc , perhaps we should consider implement Blob class on RN since we already have network and fs APIs. This may let some JS libraries that depends on web API becomes available in RN. At least we can try to make firebase.storage work.

Work in progress document

Spec Reference

These are polyfills that planned to be implemented so far

  • Blob
  • File
  • XMLHttpRequest
  • FileReader (postponed)
  • Test cases
  • Documentation

This feature will develop on branch 0.8.0

Make read/write file API easier to use

The only way to read/write file is using file stream, there should be some handy API make this easier.

for example

fs.readFile(path-to-file).then((data) => {
    // ...
})

fs.writeFile(path-to-file).then((data) => {
    // ...
})
  • IOS implementation
  • Android implementation
  • Test cases

Add config API

there will be lot of features in the future, so that current API needs to be extend, but how?

Error: `_reactNativeFetchBlob2.default.readStream is not a function`

I'm trying to use readStream, but react native is giving me the red-screen-of-death with the message, "_reactNativeFetchBlob2.default.readStream is not a function".

The package was installed using npm and linked using rnpm. And ideas?

Versions:

  • "react-native": "0.28.0"
  • "react-native-fetch-blob": "^0.6.1"
  • iPhone 6 simulator running iOS 9.3
  • XCode 7.3.1

Integration test

  • octet-stream upload
  • octet-stream download
  • multipart/form-data upload
  • multipart/form-data download
  • progress report API
  • request redirection
  • file access API

Save downloaded blob data to file system directly

The module now transforms downloaded data into BASE64 string in native context, but it will be inefficient if the developer intend to save the data into storage directly.

Perhaps there should be an option for make it more applicable.

  • Android implementation
  • IOS implementation
  • Test cases
  • Documentation

Responses come back but callback is never called

Hey, I'm seeing a strange issue on Android when I try to use this lib.
screen shot 2016-06-14 at 9 59 44 am

I'm working on an application that needs to download images from the web, and store them on device. However, as you can see, the process is completed by AsyncHTTP, but the callback itself is never called.

My code:

RNFetchBlob
.config({
fileCache: true,
path : fileName
})
.fetch('GET', tile.url, {})
.then((res) => {
console.log("Saved to " + res.path())
processedTiles++;
if (processedTiles >= tilesToBeProcessed) {
parent.onTileProcessed(card, index);
}
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.