question

oskar avatar image
oskar asked

Trying to upload files to CDN via http PUT always results in 403 forbidden

I'm running the PlayFabPowerTools source code within Visual Studio. When migrating cdn files all seems to work well up until file upload to the target title. All I get is 403 Forbidden. Any leads?

apis
10 |1200

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

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

Looks like the issue about the 403 error you are having derives from this code:

https://github.com/PlayFab/PlayFabCLI/blob/508b4fd69c3182592cb26ae4fb3325b926cc450f/PlayFabPowerTools/Utils/PlayFabExtensions.cs#L20

PlayFabPowerTools uses the WebClient class to handle file upload/download, however, it doesn’t set the contentType for the file about to upload in the headers, leaving them empty. During execution, the contentType will be set as the default value: “application/octet-stream”, which might be a problem. I set up a test to upload a png file to CDN using the code above, if I don’t add the contentType corresponding to my file, which is “image/png”, I will get the “403 forbidden” error like you did, however, if I add the contentType using this code:

client.Headers.Add("Content-Type", "image/png");

my file will get uploaded successfully.

I will report this issue to the related team to investigate, thanks for your feedback.

Meanwhile, you might want to consider re-writing corresponding code to make it specify contentType before uploading, or migrate CDN files manually, really sorry for this inconvenience.

2 comments
10 |1200

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

oskar avatar image oskar commented ·

Thank you for the quick reply. Thanks to you I've managed to make it work for our json files too.

I forked the repo and are fixing this (adding support for a few basic file types based on file extension) and a few other things. In the process now of making cloud script migration work more as you'd expect. The current way the tool migrates cloud script is by taking the latest (published or not) revision from the source title and immediately publishing it live on the target title (!). Recipe for destruction...

If I'm happy with the code in the end I might make a pull request.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan oskar commented ·

Yes, I can confirm the cloud script migrating issue you are talking about, I will report this to the corresponding team, thanks for your feedback:)

0 Likes 0 ·

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.