question

jonas.barnaby@gmail.com avatar image
jonas.barnaby@gmail.com asked

Uploading a server build via Java API

Hi everybody,

I'm trying to write an app in Java to automate our server build upload process. As of now I'm able to get the GetServerBuildUploadUrl url but I don't know how to properly upload our zip once I got it. I've been reading the Amazon documentation on the subject and, as far as I've seen, the uploading is done via an OutputStreamWriter (here: http://docs.aws.amazon.com/AmazonS3/latest/dev/PresignedUrlUploadObjectJavaSDK.html). Should I use something like the UploadObject() method shown in the documentation to serialize and upload the file? Or perhaps there's another way to upload the build other than using the AWS SDK?

Thanks!

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

No, you're correct - it's an upload to AWS S3, using a pre-signed URL, so their documentation on uploading via Java would be the way to go. Let us know if you run into any problems with this implementation.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jonas.barnaby@gmail.com avatar image
jonas.barnaby@gmail.com answered

Thanks for the advice. I'm now trying to upload the build but I keep receiving an error from Amazon. The error code is a "SignatureDoesNotMatch" with the message: "The request signature we calculated does not match the signature you provided. Check your key and signing method."

This is my code:

And this are the header fields of the HttpURLConnection:

As far as I've been able to find out, the mismatch between the access key provided by the API call and the one the S3 is receiving is most likely due to codification issues, but I'm stuck here as the solutions vary greatly depending on the language used and the SDK. Any suggestions?

Thanks in advance!

 

EDIT: based on the research I've been conducting it seems there's a known problem with the escaped characters in the security token. It appears that the %2DF and %2B characters appearing in the url retrieved by the API are decoded to / and + when the connection is opened and this messes all the process, thus returning the 403 error. But if I run a substitution then the error changes to a "malformed url" one, so I'm not sure if this is relevant.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

You also need to specify the Content-Type for the upload. By default, the Content-Type will be "binary/octet-stream", though you can override this using the ContentType (note - no dash in the name, unlike the actual header specifier) in the call to GetContentUploadUrl.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jonas.barnaby@gmail.com avatar image
jonas.barnaby@gmail.com answered

Thing is, our goal is to upload a server build. If I upload the .zip file as a content via the GetContentUploadUrl and setting properly the content-type everything works fine except for the build doesn't show as a server build but as content. Unless there's a way to set a content file as a server build this method isn't viable for us.

As for the GetServerBuildUploadUrl, which I assume is the call we need, the 403 error still persists as the call doesn't have the option to set the content-type of the request.

Any insight on how can I solve this?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Correct - as shown in the tutorial (https://api.playfab.com/docs/custom-game-servers), after you upload the build via the URL, you need to call AddServerBuild to configure it, so that it shows up. That walkthrough also shows how to set the content-type, so that you don't get the 403 error.

Alternately, you can just upload the build via the Game Manager.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jonas.barnaby@gmail.com avatar image
jonas.barnaby@gmail.com answered

Great, that was it, the content-type. If anyone is interested or ends up here looking for it, this is the code I used:

 

Provided the url is the one returned by GetServerBuildUploadUrl and the path is the path to the server build file.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jonas.barnaby@gmail.com avatar image
jonas.barnaby@gmail.com answered

Hi again

I've now completed the uploading pipeline up to the server activation, but for some reason all the builds we upload with GetServerBuildUploadUrl and AddServerBuild displays the InvalidBuildPackage status, whereas if I upload the same builds via the Game Manager they end up as available.

In case you guys want to check, they're the builds currently displayed at a our Build tab with the IDs Test008 and Test009. They're exactly the same build, the available one has been uploaded with the Game Manager and the invalid with the upload call.

What am I missing? Is there a step I'm not considering?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Hmm... I have to correct one thing from above - please use application/x-zip-compressed for the Content-Type. I was using an older reference for the call which incorrectly used binary/octet-stream. If you're still running into an issue then, can you send us the details of the AddServerBuild call you're making? Here's what I did:

  • I downloaded your Test009 build from S3
  • I used GetServerBuildUploadUrl to get a signed S3 link to upload the zip
  • I used cURL to upload the build (renamed your zip for privacy):

curl -v --insecure -H "Content-Type:application/x-zip-compressed" --upload-file MyServerBuild.zip "{ {SignedURLGoesHere}}"

  • I then called AddServerBuild, specifying the BuildId I used in the GetServerBuildUploadUrl call, and it worked

The build shows up in my title and can be made active.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jonas.barnaby@gmail.com avatar image
jonas.barnaby@gmail.com answered

Hi, Brendan.

This is the code I use for the AddServerBuild call:

"Prop" is a properties file from which I retrieve the data needed for the executable path, some variables and the command line arguments. I've checked and they're retrieved correctly. However, if you need further access to my code I can set up a private project in BitBucket and share it with you.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

What is the errorMessage you're getting back from AddServerBuild? In all cases, it will contain the additional details on why a server couldn't be added to the live builds list.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.