3

I'm trying to upload binaries in the new Web 8 way. (i've got a few gigs worth to upload).

Each time I try and upload a file, I run the following code:

StreamUploadClient _UploadClient = null;
_UploadClient = new StreamUploadClient(_endpointConfigNameUpload);
var userCredential = new System.Net.NetworkCredential(_username, _password, _domain);                                 _UploadClient.ClientCredentials.Windows.ClientCredential = userCredential;
AccessTokenData token = CoreServiceClient.GetCurrentUser();

fileUpload = _UploadClient.UploadBinaryContent(token, file.OpenRead());

and once the component is saved, I do the following:

_UploadClient.Close();
_UploadClient.Dispose();

After a few mins I get an error that :

Couldn't upload the binary file Provided access token has expired

I have performed the 2013 compatibility in my CME hoping this would stop the token from expiring (http://docs.sdl.com/LiveContent/web/pub.xql?action=home&pub=SDL%20Web-v1&lang=en-US&docid=GUID-879B67A8-71BA-4BBD-9CCE-9140B860904E&query=%2B%22AccessTokenData%22)

I've also tried adding 24 hours to the token via the token.ExpiresAt(DateTime)

But none of these changes help me with my issue. Has anyone got any advice?

Thanks in advance.

3
  • hi John, i had same issue, my work around is renew the access token if it will expire in the next 30 seconds. if (accessToken.ExpiresAt <= DateTime.Now.AddSeconds(30)) works for me
    – Lucas Liu
    Commented Jun 22, 2016 at 15:59
  • how do you renew it @LucasLiu? can you paste the solution as your answer? thanks
    – johnwinter
    Commented Jun 23, 2016 at 15:21
  • Access Tokens expire for security reasons.. Obviously, you can't make them expire later by simply changing the expiration date/time in the Access Token; that would defeat the purpose of expiration. Commented Dec 23, 2016 at 14:33

1 Answer 1

4

the quick way is checking expireAt from the access token, close current client if expires in 30 seconds and create an new client.

    public void UpdateAccessToken()
    {
        AccessTokenData accessToken = client.GetCurrentUser();
        if (accessToken.ExpiresAt <= DateTime.Now.AddSeconds(30))
        {
            client.Close();
            this.ConntectSDLCloud();
        }
    }
4
  • 1
    Lucas, see tridion.stackexchange.com/questions/14996/… on how to configure the default value and avoid the constant round-tripping here (you may still want this if you want specific events to 'refresh' the token I guess). Commented Jun 29, 2016 at 14:17
  • i didn't get that value to work @Dylan..MarkSaunders
    – johnwinter
    Commented Jun 29, 2016 at 21:10
  • ahh that's a shame - I'll leave it here for a few days in case Kunal updates (perhaps a specific restart or something along those lines is required) .. otherwise I'll delete the link :-/ Commented Jun 29, 2016 at 22:34
  • i cannot change the timeout value on SDL Cloud, but have to detect expiry time plus 30 seconds (time to call back). this works...
    – Lucas Liu
    Commented Jun 30, 2016 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.