Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

409
Views
Desea enviar imágenes usando el chat dotado con mensajes, y almacenarlas en firebase y recuperarlas, y mostrarlas en el chat

Quiero enviar imágenes con mensajes usando el chat de regalo, Aquí está mi código:

 // for send message const onSend =(messageArray) => { const msg = messageArray[0] const mymsg = { ...msg, sentBy:user.uid, sentTo:uid, createdAt:new Date() } setMessages(previousMessages => GiftedChat.append(previousMessages,mymsg)) const docid = uid > user.uid ? user.uid+ "-" + uid : uid+"-"+user.uid firestore().collection('chatrooms') .doc(docid) .collection('messages') .add({...mymsg,createdAt:firestore.FieldValue.serverTimestamp()}) }

desde aquí estoy enviando mensajes y almacenándolos en firebase y mostrando cómo recuperarlos desde firebase.

 // display code <GiftedChat messages={messages} onSend={text => onSend(text)} user={{ _id: user.uid, }} alwaysShowSend placeholder='Message' renderSend={renderSend} renderBubble={(props)=>{ return <Bubble {...props} wrapperStyle={{ right: { backgroundColor:"#efc100", }, left:{ marginLeft: -40 } }} /> }}

gracias de antemano

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Dividamos el problema en pequeños subproblemas.

  1. Obtener imagen de la biblioteca de medios
 const pickImageasync = async () => { const { status } = await ImagePicker.requestMediaLibraryPermissionsAsync(); let imgURI = null; const hasStoragePermissionGranted = status === "granted"; if(!hasStoragePermissionGranted) return null; let result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.Images, allowsEditing: true, aspect: [4, 4], quality: 1, }); if (!result.cancelled) { imgURI = result.uri; } return imgURI; };
  1. Sube una imagen a Firebase Storage
 const uploadImageToStorage= async (imgURI ) => { const ref = `messages/${[FILE_REFERENCE_HERE]}` const imgRef = firebase.storage().ref(ref); const metadata = { contentType: "image/jpg" }; // Fetch image data as BLOB from device file manager const blob = await new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); xhr.onload = function () { resolve(xhr.response); }; xhr.onerror = function (e) { reject(new TypeError("Network request failed")); }; xhr.responseType = "blob"; xhr.open("GET", imgURI, true); xhr.send(null); }); // Put image Blob data to firebase servers await imgRef.put(blob, metadata); // We're done with the blob, close and release it blob.close(); // Image permanent URL const url = await imgRef.getDownloadURL(); return url };
  1. Actualizar documento de mensaje con imagen URI permanente
 const localImgURI = "file://path_to_file" // Replace with real path of uploaded image const imgPermanentURL = await uploadImageToStorage(localImgURI) firestore().collection('chatrooms') .doc(docid) .collection('messages') .doc(messageId).update({image:imgPermanentURL})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!