question

eswitzer07 avatar image
eswitzer07 asked

Allow users to upload files with CDN

Hi all,

Just curious as to the proper way to upload files to the CDN using and unreal client SDK? I managed to get downloading working perfectly using the ClientGetContentDownloadUrlResult and using a HTTP Get to download to local storage.

However uploading seems a bit more tricky since it has to go through the admin API. Currently Im trying to do this through cloudscript, but the function Im using is probobly wrong. Ive tried the following functions:

PlayFabAdminAPI.GetContentUploadUrl(UploadRequest);

admin.GetContentUploadUrl(UploadRequest);

How should I be going about doing this? I'm unable to do a proper POST request inside unreal blueprints, since its failing due to the formatting being in POST not JSON.

Looking for some advice on the best way to approach this.

Cheers!

1 comment
10 |1200

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

eswitzer07 avatar image eswitzer07 commented ·

Edit: So I've converted the cloud script function into a HTTP request, seems a bit cleaner:

    var body = {
        Key: args.Key,
    };


    var url = "https://A041.playfabapi.com/Admin/GetContentUploadUrl";
    var content = JSON.stringify(body);
    var httpMethod = "post";
	var headers = {};
    var contentType = "application/json";
  	var secretKey = "6D4KJKTIA6C3EJGDHS7Z7ZHS7YABGSFSCQNWRNQTQ9DTUG6ZSF";


    // The pre-defined http object makes synchronous HTTP requests
    var response = http.request(url, httpMethod, content, contentType, secretKey, headers, true);
  

    log.debug(response)
    log.info(response)

But still running into an issue with this request. Inside unreal it returns a generic HTTP Request error:

LogBlueprintUserMessages: [Overview_C_83] {"Error":"CloudScriptHTTPRequestError","Message":"The script made an external HTTP request, which returned an error. See the Error logs for details.","StackTrace":"Error\n    at handlers.getSavedData (A041-main.js:75:25)"}
LogBlueprintUserMessages: [Overview_C_83] HTTP request error

0 Likes 0 ·

1 Answer

·
brendan avatar image
brendan answered

I'm very glad you posted, as trying to work around limitations is almost always the wrong thing to do. I'd strongly encourage anyone considering a workaround to get past limits to post a question specifically around what it is you're trying to do, like this, so that we can advise you on the best approach.

In this case, we specifically do not provide a Client API to upload Content to the CDN because a) you, the owner of the title, are responsible for all CDN costs on your title (pricing is listed in the File Management page of the Game Manager), and b) allowing players to upload any content, without restriction, would rapidly turn your game into an illegal fileshare service and drive your costs up massively.

For a game that uses User Generated Content, what you would need to do is have a custom game server (whether hosted by us or not) that you would have the client send the content to. It would check the content for validity before uploading it to the CDN. In addition, you'll need systems for discovery (being able to track on all the content and search it), let users rate content, let users report on infringing or offensive content, and to review those reports and remove content as needed.

We do plan to provide a UGC service for titles at a future date, but we don't have a date for that just yet.

6 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.

eswitzer07 avatar image eswitzer07 commented ·

To break it down a bit more, Im not looking to build out a full system to allow clients to upload any sort of data to the CDN, instead Im looking to upload a very specific game object to the CDN as a last second generated file - I can build out checks within the engine to ensure these are the files being uploaded.

Think the storing of a game save file thats hosted on a server that anyone can download. These save files are fairly small (usually in the 15-20kb range), so Im not massively concerned about cost and scalibility for now.

I figured storing this type of data would be best via CDN, as I would like to use playfab for all our backend needs.

Is there any other way to approach this?

0 Likes 0 ·
brendan avatar image brendan eswitzer07 commented ·

While I understand the intent, the reality of it is that if you give the client the result of the upload URL call, a hacked client doesn't have to be running your checked logic locally. It could upload literally anything. And since the call to get the signed download link is available to the client, the process would be:

1. Upload ripped movie file (or whatever) using the upload URL I get from your game.

2. Share the Key for my uploaded file on forums/IRC channels.

3. Others use that Key with the Client API call to get the download URL, and download the content.

And again, you'd be the one paying for their download usage - not something I want to see happen to any developer on our platform, which is why I advise against doing this. To be safe, the logic that checks that the uploaded content is legitimate needs to live on the server side, and it must control uploading that content to the CDN.

0 Likes 0 ·
eswitzer07 avatar image eswitzer07 brendan commented ·

Assuming then that the upload URL is only shared with a dedicated server (ran exclusively through playfab), what would be the best way to call the function to return UploadURL?

Im currently trying to handle it through cloudscript, can the Admin.GetContentUploadUrl be called through cloudscript? Is there a special way to format this request?

0 Likes 0 ·
Show more comments

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.