Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
Can't display or read file object in Javascript

I have file object and I wish to grab the URL.

screenshot of file object on Chrome console

I tried to output the properties like below, but all are giving me "undefined" except type and date.

      console.log("file: " + file.type);
      console.dir(file.attachment.attributes);
      console.dir(file.attachment.attributes.date);
      console.dir(JSON.stringify(file.attachment.attributes.author));
      console.dir(file.attachment.attributes.width);

Here's how the file type looks like as below.

screenshot of file type on Chrome console

Is there something wrong with how I try to read them?

My code is based on WordPress wp-plupload.js that comes with core WordPress. Yeah, I know I shouldn't edit the core codes but I was just experimenting.

UPDATE: Below is the code.

/**
     * After a file is successfully uploaded, update its model.
     *
     * @param {plupload.Uploader} up       Uploader instance.
     * @param {plupload.File}     file     File that was uploaded.
     * @param {Object}            response Object with response properties.
     */
    fileUploaded = function (up, file, response) {
      var complete;
   // Remove the "uploading" UI elements.
      _.each(["file", "loaded", "size", "percent"], function (key) {
        file.attachment.unset(key);
      });

      file.attachment.set(_.extend(response.data, { uploading: false }));

      wp.media.model.Attachment.get(response.data.id, file.attachment);

      complete = Uploader.queue.all(function (attachment) {
        return !attachment.get("uploading");
      });

      if (complete) {
        Uploader.queue.reset();
      }

      self.success(file.attachment);
    };

UPDATE: I just realized the file is NOT a file object after all.

  $isFile = file instanceof File;
  console.log("File? " + $isFile);

I received a "File? false". It's not a blob too! But I still wonder why I can't read the object and get the URL.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Ok, I solved the problem this way. To get the file object, I need to call file.getNative() as stated here -> https://www.plupload.com/docs/v2/File

Thanks to all for your guidance, for without you I would be a lesser coder..

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda