Code Monkey home page Code Monkey logo

Comments (8)

RonRadtke avatar RonRadtke commented on July 20, 2024 1

I'm sorry, but I either didn't read your report completely or didn't think...

The problem with expo is, you can't use any libs that rely on native code (java, obejctive-c, ...) . And this lib does rely quite strong on native code. So you can't use it together with expo.
There are basically two possibilities now:

  1. You could eject it and by that get an app you can use normally with XCode or Android Studio, or any other IDE. (https://docs.expo.io/expokit/eject/)
  2. You rewrite it to use pure js.
    Since you are currently only using it to upload a picture (or another file) this would be relatively easy.
    I hand you a small snippet of code for doing so:
 function send_file(fileuri, mimetype, filename){
    let body = new FormData(),
    data = {
        uri: fileuri,
        type: mimetype,
        name: filename
    };

    body.append('file', data);
    body.append('dirtkey', 'Hier bitte Müllwert einfügen');
    return new Promise((resolve, reject) => {
        let xhr = new XMLHttpRequest();
        xhr.addEventListener('load', (x) => {
            if (xhr.status >= 200 && xhr.status < 300) {
                resolve(xhr.response);
            }
            else {
                reject(xhr.statusText);
            }
        });
        xhr.addEventListener('error', reject);
        xhr.addEventListener('abort', reject);
        xhr.open('POST', targeturi);
        xhr.send(body);
    });
} 

Of course I would like you staying with my lib, but could understand that it's too much of a hassle for you. If you have some more questions, feel free to ask.

from react-native-blob-util.

schdief avatar schdief commented on July 20, 2024 1

thanks again for helping me out!

I tried it without headers and axios and also with XHR directly, same problem. Seems to me that formData only considers an append when you specify 3 parameters. When I add the third, the following error is thrown:

TypeError: Failed to execute 'append' on 'FormData': parameter 2 is not of type 'Blob'.

So those lines don't create a blob object:

 data = {
        uri: fileuri,
        type: mimetype,
        name: filename
    };

Which brings me back to the original state why I wanted to use your library :) So I did some more googling and came across the following code: https://github.com/schdief/reene/blob/a5ba1a9b9e01e53b4fdbcf7a23df91a5a928e7b4/reene/App.js#L222

This successfully transforms the URI to a blob and now it is recognized as an actual file at the backend.

Thanks again for all the help and sorry for not using your lib, have a nice day.

from react-native-blob-util.

RonRadtke avatar RonRadtke commented on July 20, 2024

It might be related to: #26
I assume it is built on linux, which actually cares about upper / lower case in path names. Whereas Windows (e.g. my development machine) does not care and could resolve the path correctly.
So please try if it still happens with the latest version.

from react-native-blob-util.

schdief avatar schdief commented on July 20, 2024

It might be related to: #26
I assume it is built on linux, which actually cares about upper / lower case in path names. Whereas Windows (e.g. my development machine) does not care and could resolve the path correctly.

yes I'm using MacOs

So please try if it still happens with the latest version.
I'm already using v0.13.6, did an update nevertheless, still same error

from react-native-blob-util.

RonRadtke avatar RonRadtke commented on July 20, 2024

The problem got fixed in v0.13.7. The lib is working well on iOS and simulators for iOS.
Could you post a minimal example so I can test it?

from react-native-blob-util.

schdief avatar schdief commented on July 20, 2024

The problem got fixed in v0.13.7. The lib is working well on iOS and simulators for iOS.
Could you post a minimal example so I can test it?

funny, yesterday I could only see 0.13.6 - updated to 0.13.7 now, still doesn't work, but slightly different error message:
image

you can find the whole app here, I have linked the line where I use your lib: https://github.com/schdief/reene/blob/129c836f2d77e07161072b4720d04d8c5b1e949b/reene/App.js#L43

it is still in it's early stages and I'm clearly no pro in reactive native

your help is much appreciated, thanks :)

from react-native-blob-util.

schdief avatar schdief commented on July 20, 2024

thanks a lot for the help @RonRadtke :)
I tried it before with native JS, but I couldn't get the picture to be recognized as a file at the receiving backend

the incoming request looks like this:

new request received:
{
  fields: {
    resprequ: '1',
    dirtkey: 'sonst',
    desc: 'Müll',
    rlname: 'Lohr',
    rfname: 'Steve',
    remail: '',
    rtel: '',
    lat: '51.0529371',
    lng: '13.7636763',
    date: '2021-05-15T10:31:54.365Z',
    file: '[object Object]'
  },
  files: {}
}

this output is generated by formidable and I would expect the file to be part of files and not fields, right?

you can see the backend logic here:
https://github.com/schdief/reene/blob/master/backend-mock/backend.js

the request in app is sent like this:
https://github.com/schdief/reene/blob/8c4db3c6147fc071972cf6637850d851f92f609d/reene/App.js#L84

although I'm not using your library anymore, I would be happy to get a hint what I'm doing wrong - thanks a lot :)

from react-native-blob-util.

RonRadtke avatar RonRadtke commented on July 20, 2024

I never worked with axios. So hard to say what the problem is. Compared to the stackoverflow entries (https://stackoverflow.com/questions/52830312/how-to-upload-image-to-server-using-axios-in-react-native) it seems ok. Might be your header though.
I tested my code with python flask, there it works fine and I get the file in the "files" element, not as field.

I would try to skip the headers for a test completely, to see if these are the problem. Seems to be the sole difference. Or trying pure xhr directly.
Also, it seems iOS is sometimes using 3 backslashes after file, so file:/// instead of file:// . You might have to check and correct this too

from react-native-blob-util.

Related Issues (20)

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.