0

Hi i tried to upload file with expo: the console.log give me this error "Streaming file uploads via req.file() are only available over HTTP with Skipper" but when i tried it with postman it's workd.I use sailsJs for my back-end this is my code for my expo react

const[imageUri, setImageUri]=useState()
    const[imageUpload, setImageUpload]=useState()
    const selectImage = async()=>{
        try {
            const result = await ImagePicker.launchImageLibraryAsync();
            if(!result.cancelled)
            setImageUri(result.uri)
            setImageUpload(result)
        } catch (error) {
            console.log('Error running on image')
        }
       
    }
const handleSubmit = async () => {
        const dataDemande = {
            projectTitle: titre,
            material: materiel,
            description: description,
            projectType: checked,
            lieuRendezvous: value_3,
            idClient: props.route.params.id,
            model: imageUpload
        };
        console.log(dataDemande);
        var res = await demandeClient(dataDemande);
        console.log(res);
        props.navigation.navigate("Tableau de bord - Client");
    };

and this is the code from the back-end

findCouturierAndCreateDemande: async function (req, res) {
    var recherche = req.body
    req.file('model').upload({
      adapter: require('skipper-gridfs'),
      uri: 'mongodb://localhost:27017/image'
    }, async function (err, filesUploaded) {
      if (err) return res.serverError(err);
      console.log(filesUploaded[0].fd)
      var couturier = await Client.find({
        where: {
          isCouturier: true,
          ville: { contains: recherche.ville },
          adresse: { contains: recherche.adresse },
          rue: { contains: recherche.rue },
        },
      })
      var img = await Image.create(_.omit(filesUploaded[0], ['status', 'field', 'extra'])).fetch()
      var newDemande = await Demande.create({
        titre: recherche.projectTitle,
        materiel: recherche.material,
        description: recherche.description,
        service: recherche.projectType,
        positionActivity: recherche.lieuRendezvous,
        client: recherche.idClient,
        modelImage: img.id
      }).fetch()
      console.log(img)
      return res.ok({couturier, newDemande})
    });
  }
2
  • See how he uploads file here - stackoverflow.com/a/63571279/1828637 Commented Aug 30, 2020 at 23:16
  • thanks a lot @Noitidart, that's help me Commented Sep 3, 2020 at 18:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.