Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete/Upload Image throws an Bad Request Error #1798

Closed
naimo84 opened this issue May 12, 2022 · 6 comments
Closed

Delete/Upload Image throws an Bad Request Error #1798

naimo84 opened this issue May 12, 2022 · 6 comments

Comments

@naimo84
Copy link

naimo84 commented May 12, 2022

Tandoor Version

Current Version: develop Ref: 3789388

Setup

Kubernetes

Reverse Proxy

Nginx Proxy Manager (NPM)

Other

No response

Bug description

Hi @vabene1111,

I'm trying to upload an image via Rest-API, but it's failing with an error 400 (Bad Request). The same error occurs, if I want to delete some image on the frontend (as you can see on the screenshot). Unfortunately the logs don't offer any more information, what i'm doing wrong (DEBUG is set to 1)

The frontend error might be a bug I think. The Rest-Api is definitely on my side ;)

Thanks and kind regards from Bavaria,
Benjamin

async function uploadImage(id, mongoid) {

  // If you need the binary data as a Buffer
  // create one from data chunks    
  const got = await import('got');

  var formData = {
    name: 'image',
    file: {
      value: fs.createReadStream(`/home/rezepte/${mongoid}`),
      options: {
        filename: `${mongoid}.png`,
        contentType: 'image/png'
      }
    }
  };

  await got.default.put(`https://tandoor.dev/api/recipe/${id}/image/`, {
    headers:
    {
      Authorization: "Token e12346568145a7937c22fd80e9f93e50244b6789",
      'Content-Type': 'multipart/form-data'
    },
    _form: formData,
  })
}

image

Relevant logs

10.42.0.0 - - [12/May/2022:13:13:04 +0200] "PUT /api/recipe/21/image/ HTTP/1.1" 400 2 "https://tandoor.dev/edit/recipe/internal/21/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36"
59
Bad Request: /api/recipe/21/image/
58
10.42.0.0 - - [12/May/2022:13:13:09 +0200] "GET /edit/recipe/internal/21/ HTTP/1.1" 200 18922 "https://tandoor.dev/view/recipe/21" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36"
57
10.42.0.0 - - [12/May/2022:13:13:09 +0200] "GET /manifest.json HTTP/1.1" 200 1325 "https://tandoor.dev/edit/recipe/internal/21/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36"
56
Bad Request: /api/recipe/21/image/
@vabene1111
Copy link
Collaborator

i will need to look at the frontend but if you are using the rest api make sure to do form/multipart to properly transmit the data

@naimo84
Copy link
Author

naimo84 commented May 14, 2022

Many many thanks for looking at the frontend 👍

I found a workaround 😁 Uploading an image_url works like a charm 👍
Therefore I must me doing something wrong with the binary data...

Is it possible to output some more informations in the error log? DEBUG=1 doesn't work for me?

I have another case: Updating an recipe with PUT also leads me to an HTTP400 and i don't see, what I'm doing wrong ;)

@vabene1111
Copy link
Collaborator

generally speaking you should get a descriptive error message as a json response to your API requests, have you looked at those ?

@naimo84
Copy link
Author

naimo84 commented May 16, 2022

Yes, I expected you see an error there 😉 But it's empty as you can see here for deleting an picture via frontend:

image

Many many thanks for getting into this issue 👍

@vabene1111
Copy link
Collaborator

interesting, will take a look, thanks

@vabene1111
Copy link
Collaborator

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants