Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49240

Filetransfer upload media to wordpress works locally 400 error on remote

$
0
0

@dcrash wrote:

Hello Ionic people,
The code works on localhost get generates a 400 error - No data supplied on a clean lightsail bitnami with only the jwt plugin installed.

{“code”:1,“source”:“data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJ…….”,“target”:“http://xxx.xxx.xx.xxx/wp-json/wp/v2/media",“http_status”:400,“body”:"{“code”:“rest_upload_no_data”,“message”:“No data supplied.”,“data”:{“status”:400}}”,“exception”:“http://xxx.xxx.xxx.xxx/wp-json/wp/v2/media”}

localhost gets this
{bytesSent: 52752, responseCode: 201, response: “{“id”:16,“date”:“2019-09-21T20:24:13”,“date_gmt”:”…"https://api.w.org/{rel}",“templated”:true}]}}", objectId: “”}

code -

 uploadImage(img){
  let options: FileUploadOptions = {
     fileKey: "file",
     fileName: 'funtimepic.jpg',
     mimeType: 'image/jpeg',
     headers :{
         'Authorization': `Bearer ${this.user.token}`,
       'Content-Disposition':'attachment; filename=/"funtimepic.jpg/"'
     }  
  }
    const fileTransfer: FileTransferObject = this.transfer.create();
  fileTransfer.upload(img, this.config.wordpressApiUrl + '/wp/v2/media', options)
   .then((data) => {
     console.log(data)  
   }, (err) => {
	console.log(JSON.stringify(err)) ;
	})   
  };

I poked around wordpress and it looks like its going thru here:

// Get the file via $_FILES or raw data.
		$files   = $request->get_file_params();
		$headers = $request->get_headers();

		if ( ! empty( $files ) ) {
			$file = $this->upload_from_file( $files, $headers );
		} else {
			$file = $this->upload_from_data( $request->get_body(), $headers );
		}


	protected function upload_from_data( $data, $headers ) {
		if ( empty( $data ) ) {
			return new WP_Error( 'rest_upload_no_data', __( 'No data supplied.' ), array( 'status' => 400 ) );
		}

thanks for your help.
Jim

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49240

Trending Articles