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

[Upload Media API] Cannot upload photo from bytes. #5

Open
brianwu291 opened this issue Jan 24, 2021 · 5 comments
Open

[Upload Media API] Cannot upload photo from bytes. #5

brianwu291 opened this issue Jan 24, 2021 · 5 comments

Comments

@brianwu291
Copy link

Recently I use the upload API from bytes(follow this API Docs), but I failed to upload the photo. Here is my code:

const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", `Bearer ${accessToken}`);
const requestOptions = {
 method: 'POST',
 headers: myHeaders,
 redirect: 'follow'
};
fetch("https://mybusiness.googleapis.com/v4/accounts/*******/locations/******/media:startUpload", requestOptions)
 .then(res => res.json()) // here I got correct format response like this {  resourceName: '******'  }
 .then(res => {
     const myHeaders = new Headers();
     myHeaders.append("Authorization", `Bearer ${accessToken}`);
     myHeaders.append("Content-Type", "image/jpeg");
     const file = "<file contents accessed by input element event listener.>";
     const requestOptions = {
         method: 'POST',
         headers: myHeaders,
         body: file,
         redirect: 'follow'
     };
     return fetch(`https://mybusiness.googleapis.com/upload/v1/media/${res.resourceName}?upload_type=media`, 
       requestOptions)
      .then(result => {
        console.log(result)  // got nothing but empty string, status code is 200.
        return res;
      }) 
 })
 .then(res => {
       const myHeaders = new Headers();
       myHeaders.append("Content-Type", "application/json");
       const raw = JSON.stringify({"mediaFormat":"PHOTO","locationAssociation":{"category":"ADDITIONAL"},"dataRef":{"resourceName":`${res.resourceName}`}});
      myHeaders.append("Content-Type", "application/json");
      const requestOptions = {
         method: 'POST',
         headers: myHeaders,
         body: raw,
         redirect: 'follow'
      };
       fetch("https://mybusiness.googleapis.com/v4/accounts/****/locations/****/media", requestOptions)
         .then(response => response.json())
         .then(result => console.log(result))
         .catch(error => console.log('error', error));
 })

after the last request, I got the following error response:

{
    "error": {
        "code": 400,
        "message": "Request contains an invalid argument.",
        "status": "INVALID_ARGUMENT",
        "details": [
            {
                "@type": "type.googleapis.com/google.mybusiness.v4.ValidationError",
                "errorDetails": [
                    {
                        "code": 1000,
                        "message": "Fetching image failed."
                    }
                ]
            }
        ]
    }
}

Does something I did wrong?

@YevhenKovalevskyi
Copy link

Have you solved this issue?

@driss-ben
Copy link

Did you fixe the issue ?

@gybandi
Copy link

gybandi commented Aug 28, 2023

Did you fixe the issue ?

I was having the same issue as OP and last year I contacted google business API team about it. They've recently replied that it seems to be a bug in the API and they added this to their public issue tracker:
https://issuetracker.google.com/issues/293595949

@driss-ben
Copy link

So there is no solution right now ?

@gybandi
Copy link

gybandi commented Aug 28, 2023

It seems that way, at least I haven't found any.

You could use the "Upload from a URL" method described here:
https://developers.google.com/my-business/content/upload-photos
This seems to be working, but for me it wasn't a viable solution

Edit: perhaps you can click on the "I'm impacted" (+1) button on the link I posted above, maybe that will move the issue up in priority

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

4 participants