Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8965905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:54:43+00:00 2026-06-15T16:54:43+00:00

I’m wondering if anyone can tell me the proper syntax & formatting for a

  • 0

I’m wondering if anyone can tell me the proper syntax & formatting for a service account to send a POST Object to bucket request? I’m attempting it programmatically using the HttpComponents library. I manage to get a token from my GoogleCredential, but every time I construct the POST request, I get:

HTTP/1.1 403 Forbidden

<?xml version='1.0' encoding='UTF-8'?><Error><Code>AccessDenied</Code><Message>Access denied.</Message><Details>bucket-name</Details></Error>

The Google documentation that describes the request methods, mentions posting using html forms, but I’m hoping that wasn’t suggesting the ONLY way to get the job done. I know that HttpComponents has a way to explicitly create form data by using UrlEncodedFormEntity, but it doesn’t support multipart data. Which is why I went with using the MultipartEntity class. My code is below:

MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );
String token = credential.getAccessToken();
entity.addPart("Authorization", new StringBody("OAuth " + token));
String date = formatDate(new Date());
entity.addPart("Date", new StringBody(date));
entity.addPart("Content-Type", new StringBody("multipart/form-data"));
entity.addPart("bucket", new StringBody(bucket));
entity.addPart("key", new StringBody("fileName"));
entity.addPart("success_action_redirect", new StringBody("/storage"));
File uploadFile = new File("pathToFile");
FileBody fileBody = new FileBody(uploadFile, "text/xml");
entity.addPart("file", fileBody);
httppost.setEntity(entity);
System.out.println("Posting URI = "+httppost.toString());
HttpResponse response = client.execute(httppost);
HttpEntity resp_entity = response.getEntity();

As I mentioned, I am able to get an actual token, so I’m pretty sure the problem is in how I’ve formed the request as opposed to not being properly authenticated.

Keep in mind:

  1. This is being performed by a service account.
  2. Which means that it does have Read/Write access

Thanks for reading, and I appreciate any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:54:45+00:00Added an answer on June 15, 2026 at 4:54 pm

    It looks like you are conflating PUT and POST methods, given that you are using an OAuth access token that only works with PUT and form fields which only work with POST.

    The easiest way to upload an object will be to use something like the following:

    HttpPut put = new HttpPut("https://storage.googleapis.com/" + BUCKET + "/" + OBJECT);
    put.addHeader("Authorization", "Bearer " + credential.getAccessToken());
    put.setEntity(new StringEntity("object data"));
    client.execute(put);
    

    It is also possible, but more complicated than just using a PUT, to create a signed HTML form that users can use to upload objects using POST. Your form requires a signed policy document similar to the following:

    PolicyDocument = {"expiration": "2010-06-16T11:11:11Z",
     "conditions": [
       ["starts-with", "$key", "" ],
       {"acl": "bucket-owner-read" },
       {"bucket": "travel-maps"},
       {"success_action_redirect": "http://www.example.com/success_notification.html" },
       ["eq", "$Content-Type", "image/jpeg" ],
       ["content-length-range", 0, 1000000]
      ]
    }
    Policy = Base_64_Encoding_Of(PolicyDocument)
    MessageDigest = Sha256_With_RSA(SecretKey, Policy)
    Signature = Base64_Encoding_Of(MessageDigest)
    

    which results in the following HTML:

    <form action="http://travel-maps.storage.googleapis.com" method="post" enctype="multipart/form-data">
    <input type="text" name="key" value="">
    <input type="hidden" name="bucket" value="travel-maps">
    <input type="hidden" name="Content-Type" value="image/jpeg">
    <input type="hidden" name="GoogleAccessId" value="1234567890123@developer.gserviceaccount.com">
    <input type="hidden" name="acl" value="bucket-owner-read">
    <input type="hidden" name="success_action_redirect" value="http://www.example.com/success_notification.html">
    <input type="hidden" name="policy" value="ajUJTm9jAHADNmF0aW9uIjogIjIwMTAtMDYtMTZUMTSAMPLEE6MTE6MTFaIiwNCSAMPLEiAgWyJzdGFydSAMPLEAiaHR0cDovL3maWNhSAMPLEIiB9LASAMPLEWN0aW9uX3JlZGlyZW">
    <input type="hidden" name="signature" value="BSAMPLEaASAMPLE6SAMPLE+SAMPPLEqSAMPLEPSAMPLE+SAMPLEgSAMPLEzCPlgWREeF7oPGowkeKk7J4WApzkzxERdOQmAdrvshKSzUHg8Jqp1lw9tbiJfE2ExdOOIoJVmGLoDeAGnfzCd4fTsWcLbal9sFpqXsQI8IQi1493mw=">
    
    <input name="file" type="file">
    <input type="submit" value="Upload">
    </form>
    

    Note the policy and signatures fields as well as the other hidden fields, which match the conditions specified in the policy document. Specifically bucket == travel-maps, acl == bucket-owner-read, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
i got an object with contents of html markup in it, for example: string
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.