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

124
Views
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 answers
Answer question

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 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!