我正在使用https://github.com/WP-API/node-wpapi,我正在尝试通过REST API将媒体上传到wordpress 但是在使用react-native-image-picker在react native中选择文件并将图像上传到https://****.com/wp-json/wp/v2/media
时const WPAPI = require('wpapi');
const wp = new WPAPI({
endpoint: 'https://****.com/wp-json/',
username: '****',
password: '****'
});
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
wp.media()
.setHeaders({
'Content-Disposition': `form-data; filename=${response.fileName}`,
})
// Specify a path to the file you want to upload, or a Buffer
.file(response.uri) //file location
.create({
title: 'My awesome image',
alt_text: 'an image of something awesome',
caption: 'This is the caption text',
description: 'More explanatory information'
})
.then(function (response) {
console.log(response)
})
.then(function (response) {
console.log(response);
}).catch(error=>console.log(error));
}
});
但是上传图片时出现此错误,请帮忙
{code: "rest_upload_no_data", message: "No data supplied.", data: {…}}