node-wpapi icon indicating copy to clipboard operation
node-wpapi copied to clipboard

Cannot upload media

Open tridnguyen97 opened this issue 4 years ago • 8 comments

Environment

nodejs: 10.14.1
wpapi: ^1.2.1

Step to reproduce

Attempt the following code:

const WPAPI = require('wpapi');

var wp = new WPAPI({ 
    endpoint: 'https://www.mysite.com/wp-json',
    username: "my_username",
    password: "my_password"
  })

wp.media()
    // Specify a path to the file you want to upload, or a Buffer
    .file( 'path/to/file.jpg' )
    .create({
        title: 'My awesome image'
      })
      .then(res => {
        console.log(res)
      })

Expected result

New media would be uploaded

Actual result

All existed media is returned

tridnguyen97 avatar Apr 18 '20 06:04 tridnguyen97

Just to confirm, do you have the Basic Auth plugin installed and active?

kadamwhite avatar Apr 21 '20 13:04 kadamwhite

I was using Basic Auth for testing the API.

tridnguyen97 avatar Apr 21 '20 14:04 tridnguyen97

Same problem here, any updates or solutions?

asiz15 avatar Sep 18 '20 02:09 asiz15

same issue here

parkerproject avatar Nov 05 '20 22:11 parkerproject

same for me. Just try to reproduce the example and got an error, don't know if you got the same error ?

Failed to execute 'append' on 'FormData': parameter 2 is not of type 'Blob'.

Cchumi avatar Nov 09 '20 17:11 Cchumi

@Cchumi Had the same issue. The media file must be uploaded from a nodejs server. It won't work out of the box via Reactjs, at least from my experience.

vedadf avatar Nov 17 '20 01:11 vedadf

Works properly on WP5.4 but had the same problem mentioned here on WP4.7.3. I think this is related to WordPress version being targeted

azizfcb avatar Oct 05 '21 14:10 azizfcb

Hi. For everyone who is facing this problem for me worked after adding "s" to http: https://mywebsite.com

stevecode21 avatar Dec 10 '21 23:12 stevecode21