0

React-native, Redux를 사용하고 있습니다.이미지를 저장소에 업로드 한 후 firebase 업데이트 데이터베이스

NPM "중포 기지" "^ 4.6.0" "반응 - 네이티브-덩어리를 가져"이미지

나는 이미지를 업로드 한 후 중포 기지를 사용하여 데이터베이스에 이미지 URL을 추가하려고를 blobing에 대한 .

이미지를 저장소에 업로드하거나 데이터베이스의 데이터를 업데이트 할 수는 있지만 둘 다 수행 할 수는 없습니다.

는 (성공/실패)

만 100 % 작동 기능 모두를 내가 데이터를 업데이트하기 위해 호출 이미지를 업로드하고 응답을 받고 없습니다 후, 나는 또 다른 후 하나를 호출 할 수 없습니다. 나는 명확하게해야합니까? 다시 놓기? 그렇다면 어떻게?

이미지 업로드 :

const db = firebase.firestore();... 
db.collection("reports").doc(uId).collection("user-reports") 
     .add({ 
      "title": "report title...", 
      "discription": "discription..."}) 
     .then(() => { 
      console.log("Document successfully written!"); 
      dispach({ 
       type: types.FIREBASE_REPORT_ADD, 
       payload: "Added Report" 
      }) 
     }) 
     .catch((err) => { 
      console.error("Error writing document: ", err); 
     }); 

업로드 데이터 :

const imageRef = storageRef.child(`images/${uId}/${CREATION_TIME}`); 
return (dispach) => { 

fs.readFile(imagePath, 'base64') 
    .then((data) => { 
     //console.log(data); 
     return Blob.build(data, { type: `${mime};BASE64` }) 
    }) 
    .then((blob) => { 
     uploadBlob = blob; 
     return imageRef.put(blob, { contentType: mime }) 
    }) 
.then(() => { 
    uploadBlob.close() 
    return imageRef.getDownloadURL() 
}) 
.then((url) => { 
    console.log("some url:",url) 
    dispach({ 
      type: types.FIREBASE_REPORT_IMAGE_UPLOADED, 
      payload:url 
     }) 
}) 
.catch((error) => { 
    console.log("Blob err: ",error); 
    dispach({ 
      type: types.FIREBASE_REPORT_IMAGE_UPLOADED, 
      payload:null 
     }) 
}); 
} 
+1

저장 용량을 업로드 할 때 콜백이 필요합니다. 이를 사용하여 파일 URL을 데이터베이스에 씁니다. 이것은 꽤 일반적인 관행입니다. 거기에 문제가 있습니까? 더 자세하게 얘기해 주 시겠어요? 코드를 보여줄 수 있습니까? –

+0

당신은 firebase 가져 SDK를 사용하고 있습니까? –

+0

나는 firebase를 사용 중입니다. ":"^ 4.6.0 ""react-native-fetch-blob " – amos

답변

0

내가 "BLOB를"살고 base64로 내 이미지를 업로드로 고정. 과 같이 :

ref.putString(message, 'base64').then(function(snapshot) { 

을 console.log ('base64로 문자열을 업로드!'); }});

매우 부드럽게 작동합니다.

관련 문제