bananalopa avatar image
bananalopa asked

Uploading any file (not empty) to the entity


I am trying to upload binary data using entities system, but in unity sdk there is:

    public class InitiateFileUploadsRequest : PlayFabRequestCommon
        /// <summary>
        /// The entity to perform this action on.
        /// </summary>
        public EntityKey Entity;
        /// <summary>
        /// Names of the files to be set. Restricted to a-Z, 0-9, '(', ')', '_', '-' and '.'
        /// </summary>
        public List<string> FileNames;
        /// <summary>
        /// The expected version of the profile, if set and doesn't match the current version of the profile the operation will not
        /// be performed.
        /// </summary>
        public int? ProfileVersion;

No field for data. Only file name.

So from the client side I can create only empty file in the entity on the server.

Is there a way to actually upload files from client side using entity system?

Is unity sdk missing some code, or is it not supporting by api at all at the moment?

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

JayZuo avatar image
JayZuo answered

To upload files to entity, please refer to Getting Started with Entities, especially the Entity Files section. InitiateFileUploadsRequest is used for initiating file uploads, it only has file names. When you call PlayFabDataAPI.InitiateFileUploads successfully, you will get a InitiateFileUploadsResponse. In which, each FileName will have a corresponding UploadUrl. And this URL is where your file should be sent to via an HTTP PUT operation.

10 |1200

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

bananalopa avatar image bananalopa commented ·

Oh, I see, I missed it. Thank you for the response!

0 Likes 0 ·
moaz0005 avatar image moaz0005 commented ·

What is the difference between InitiateFileUploads and GetContentUploadURL?

I just want to allow user to upload profile picture / avatar file from his device. P.S I need the url to update player avatar.

Is it possible to upload file with InitiateFileUploads within the limits of free tier? As, what I have come to know so far is that CDN is a paid service and for that I have to upgrade the tier.

0 Likes 0 ·
Andy avatar image Andy ♦♦ moaz0005 commented ·

The primary difference is one uses a CDN and one is stored locally to PlayFab's service infrastructure. Files uploaded to entities using InitiateFileUploads are much more limited in number and overall size. The advantage, in exchange for staying within the limits, is you don't pay per downloaded byte.

For your use case, a file attached to the player entity may make sense, but do be careful about how often that file is accessed. If the player is at the top of a leaderboard, is every other player going to be downloading her avatar? That wouldn't work. Also be aware that the overall file size in the free tier is limited to 1GB.

1 Like 1 ·

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.