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

228
Views
Subir imágenes a Firestore como un archivo 9B

Estaba tratando de cargar una imagen en mi almacenamiento de Firebase, se está cargando como un archivo 9b y no puedo abrirlo. no muestra ningún mensaje de error. carga y da la url. pero en la url está rota y muestra un error al cargar la vista previa en el almacenamiento de firebase

 /** @type {any} */ const metadata = { contentType: 'image/png', }; // Upload file and metadata to the object 'images/mountains.jpg' const storageRef = ref(storage, 'products/' + file.name); const uploadTask = uploadBytesResumable(storageRef, file, metadata); // Listen for state changes, errors, and completion of the upload. uploadTask.on('state_changed', (snapshot) => { // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100; console.log('Upload is ' + progress + '% done'); switch (snapshot.state) { case 'paused': console.log('Upload is paused'); break; case 'running': console.log('Upload is running'); break; } }, (error) => { // A full list of error codes is available at // https://firebase.google.com/docs/storage/web/handle-errors switch (error.code) { case 'storage/unauthorized': // User doesn't have permission to access the object break; case 'storage/canceled': // User canceled the upload break; // ... case 'storage/unknown': // Unknown error occurred, inspect error.serverResponse break; } }, () => { // Upload completed successfully, now we can get the download URL getDownloadURL(uploadTask.snapshot.ref).then((downloadURL) => { console.log('File available at', downloadURL); });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

En la función de carga, debe verificar si el usuario realmente seleccionó el archivo. También intente usar la función uploadBytes en su lugar:

 import { getStorage, ref, uploadBytes } from "firebase/storage"; var fileImage1 = $("#chooseImg").val(); if (!file) { console.log("No File Selected") } else { const storageRef = ref(storage, 'products/' + file.name); uploadBytes(storageRef, file).then((snapshot) => { console.log('Uploaded a blob or file!'); }); }
about 4 years ago · Juan Pablo Isaza Report

0

const uploadTask = uploadBytesResumable(storageRef, file, metadata);

la variable de file que está pasando para cargar contiene el tipo de datos incorrecto. Asegúrese de que sea un Blob y no otro tipo de datos. Estaba tratando de cargar el resultado de reader.readAsDataURL(file); y se comportó igual ~ solo 9b de metadatos.

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!