gamesparks uploading image and avaiable all to download support

How to Upload Binary Content Direct from your Game

You can give your players the power to upload binary content to be hosted on the GameSparks platform and, from there, shareable with other players. The manner to practice this is fairly straightforward and you must consummate the following steps:

  1. Request a URL from the platform to which y'all can upload the content.
  2. Upload the content to the URL provided by the platform.
  3. Once content has been uploaded, you'll want the player (or other players) to be able to retrieve the content for use.

In this exercise we'll run through how you complete each of these steps with the GameSparks API and demonstrate this using the Test Harness. To finish, there is a cursory notation on using the GameSparks SDKs to perform these steps (which we've streamlined behind the scenes to make your life easier).

Upload File Size Limit? For the file size limit imposed on uploaded content, see System Limits.

Go an Upload URL

The first footstep is to go an upload URL - you need somewhere to mail your content. If you're following these steps in the Test Harness, the GetUploadUrlRequest is bachelor nether the Upload category (brand certain yous've authenticated as a role player before making the beginning asking).

A GetUploadUrlRequest made past an authenticated player will event in a response containing a url attribute.

URL Attribute has limited Lifespan! Upload URLs are i-shot URLs that expire after a matter of minutes and then don't hang onto them - if you don't utilise it right abroad, throw it away and request another i.

          {            "@class":            ".GetUploadUrlRequest"            }                  
          {            "@course":            ".GetUploadUrlResponse",            "url":            "https://gsp-aeu000-se04.gamesparks.cyberspace/upload/288934CFkBXg/16fc457d-656e-47ea-ad28-00595ec04054/3d3cbd17d2584e8295756d021dd0888b"            }                  

Upload the Content

At present that you have the upload URL yous need to post the file. This is washed using a multipart/form-data post - we'd recommend checking information technology out in the Exam Harness considering we've provided a widget that will do this for you. When using the SDKs, run into SDK Usage section below.

one. In the portal, navigate to Configurator>Examination Harness.

2. Authenticate every bit a player you lot've registered previously.

3. Under Requests, click on Upload and select GetUploadUrlRequest.

Metadata? Notation that the GetUploadUrlRequest has an uploadData parameter. Yous can use this to enter some metadata, which volition be stored confronting the player'due south uploaded binary content. For this instance, you can remove this parameter earlier submitting the request.

4. Remove the uploadData parameter and submit the GetUploadUrlRequest. You'll see a GetUploadUrlResponse in the Inspector window and the upload Url is automatically entered into the URL field:

5. Under File, click Browse to select the file y'all want to upload equally binary content to the platform.

6. When you've selected the file you want to upload, click Upload:

  • An UploadCompleteMessage shows in the Inspector window.
  • An Uploading button appears at the top of the page and when the upload completes, you can click on this to review your uploads to the platform:

Being an HTTP Mail, this is not done through the WebSocket. However, when the upload is complete, the authenticated WebSocket that was used to request the upload URL will receive an UploadCompleteMessage indicating that the upload was successful:

          {            "@course":            ".UploadCompleteMessage",            "messageId":            "5832edaf3a32df04983a8960",            "notification":            truthful,            "playerId":            "5818aef23a32df04ae8d53ed",            "summary":            "Your upload is complete",            "uploadData": {            "fileName":            "634c80176da1458d965692c87c3a8e68-My Document.txt",            "uploadId":            "634c80176da1458d965692c87c3a8e68",            "fileSize":            30,            "origFileName":            "My Certificate.txt",            "playerId":            "5818aef23a32df04ae8d53ed"            },            "uploadId":            "634c80176da1458d965692c87c3a8e68"            }                  

Inside the message is an uploadData aspect which contains all the information about the upload:

  • If you had used the uploadData parameter to submit some metadata with the GetUploadedRequest, this would exist shown in the UploadCompleteMessage. However, you cannot use the uploadData parameter to overwrite the organisation attributes returned in the UploadCompleteMessage - even if you lot had submitted, for case, an origFileName with the request, this will non overwrite the organization-generated value for this attribute.
  • Make sure y'all hold on to the uploadId, considering we'll need information technology in the next pace.

Call up the Content

The terminal pace is to actually retrieve the content that has been uploaded.

i. In the Test Harness click Misc under Requests and select GetUploadedRequest which takes an uploadId (which we received from the UploadCompleteMessage):

          {            "@class":            ".GetUploadedRequest",            "uploadId":"635ec5dda1bc40b9b53e30618e1d8fff"            }                  

A GetUploadedResponse is returned, which contains a URL we can use to download the content. Every bit before, this URL is fourth dimension-sensitive and so don't hang onto it for long - request ane as you demand it.

                      {            "@form":            ".GetUploadedResponse",            "size":            xxx,            "url":            "https://gamesparkstestbinaries.blob.core.windows.internet/upload-358719/635ec5dda1bc40b9b53e30618e1d8fff-My%20Document4.txt?sig=AP7P%2BttABetqCBxeq9TfmUL0E5jYa1bVaNFh6WoTYqg%3D&st=2016-11-21T13%3A47%3A21Z&se=2016-11-21T14%3A02%3A21Z&sv=2015-04-05&sp=r&sr=b&gsstage=preview"            }                  

2. Go alee and examination the URL you receive by pasting information technology into your accost bar in the browser. Y'all should exist able to download the content yous uploaded in the before step.

uploadId not Tied to 1 Thespian! The uploadId is non tied to a specific player, then if you lot were to transport that uploadId to another player, the other player could too use it to request a download URL. This means you can permit your players to share content by sending the uploadIds to other players.

Deleting Uploaded Files

When managing your uploaded files, you tin can utilize the deleteUploadedFile SparkFiles method to delete uploaded files.

SDK Usage

Upload

For completeness nosotros betrayal the method getUploadUrlRequest to build the request object to get a URL to mail service the upload to. However, there's an additional method nosotros provide chosen uploadFile that takes a file, fileName, and optional metadata nearly the upload. This wraps the request to get an upload URL and the subsequent upload of the file and presents them every bit a single functioning(Unity only).

                      GSAndroidPlatform            .gs().getRequestBuilder().createGetUploadUrlRequest()            .send(new GSEventConsumer<GSResponseBuilder.GetUploadUrlResponse>() {            @Override            public void onEvent(GSResponseBuilder.GetUploadUrlResponse getUploadUrlResponse) {            if            (!getUploadUrlResponse.hasErrors()) {                     Arrangement.out            .println("upload URL is "            + getUploadUrlResponse.getUrl());                 }             }         });                  

Download

Equally with the upload, nosotros betrayal the method getUploadedRequest to build the request object to go a URL to download the file. However, there'southward an additional method getUploadedFile which takes the uploadId and wraps up requesting the download URL and performing the download itself and presents them equally a unmarried operation.

                      GSAndroidPlatform            .gs().getRequestBuilder().createGetUploadedRequest()            .setUploadId(uploadId).transport(new GSEventConsumer<GSResponseBuilder.GetUploadUrlResponse>() {            @Override            public void onEvent(GSResponseBuilder.GetUploadedResponse getUploadedResponse) {      } });                  

Others

We haven't nonetheless added the above convenience methods for any of the SDKs apart from the Android and Unity SDKs, then for now you'll need to implement the multipart postal service yourself. We won't go into the details of exactly how to implement this here because there are many slap-up resources already available that cover this. What you exercise need to know is that the parameter name against which the binary content is posted is file.

auldwhicard.blogspot.com

Source: https://docs.gamesparks.com/tutorials/database-access-and-cloud-storage/uploading-binary-content-from-game.html

0 Response to "gamesparks uploading image and avaiable all to download support"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel