question

miquelroan avatar image
miquelroan asked

Uplaoding files via PHP SDK

Hello, I 've struggling trying to upload files to entities via PHP SDK.

Now I 've found that the problem may be the headers, since documentation says:

Security

EntityToken

This API requires an Entity Session Token, available from the Entity GetEntityToken method.

Type: apiKey
In: header

But I'm not sure how to include these headers in the PHP API call

I tried calling

header('EntityToken: "'.$loginResult->data->EntityToken->EntityToken.'"',true);

before API call invocation. But I always get:

errorMessage -> "EntityTokenInvalid"

Although I'm still not sure if this is thje problem

Best Regards

entities
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

You are trying to call InitiateFileUploads using PHP SDK, is that correct? In that case, looking at the code:

https://github.com/PlayFab/PhpSdk/blob/c94e84b3764b9467122808b346fb5dee5b839ddf/PlayFabSDK/PlayFabDataApi.php#L70

    public static function InitiateFileUploads($titleId, $entityToken, $request)
    {
        //TODO: Check the entityToken


        $result = PlayFabHttp::MakeCurlApiCall($titleId, "/File/InitiateFileUploads", $request, "X-EntityToken", $entityToken);
        return $result;
}

Therefore, you should simply pass the EntityToken as a parameter in the InitiateFileUploads API call.

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

miquelroan avatar image miquelroan commented ·

Hello,your solution is working.

I was following the example included in the SDK and that brought me to confusion.

On the other hand, I'm not being able to make the Playfab server accept my connection to send the file. This is how I'm trying:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $resultjson->data->UploadDetails[0]->UploadUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . filesize($filepath)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, "@".$filepath);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 61); 
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
$response = curl_exec($ch);
curl_close($ch);

My curl_exec call is always returning request timeout:

Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.

Is there something I'm doing wrong?

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

Hi, sorry for the late response.

Sorry that I am not very familiar with the PHP cURL lib, however, you may find this tutorial demonstrating a full entity file loop (in C#) helpful.

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

what's the URL?
Thank you!

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.