I’m dealing with Document Translator using c#, and after trying almost everything, I’m still getting the response:
“Cannot access source document location with the current permissions.
Status: 200 (OK)
ErrorCode: InvalidRequest
The fact is that I only get this message when I use a Blob SAS only to translate one document which is in a container. This is (for example):
Uri blobSourceURI = new Uri(“https://” + sAccountName + “.blob.core.windows.net/” + _Containername + “/test.txt?” + SASTokenBLOB);
But when I use the Container Blob SAS, without expecifying the Blob name.... it works fine!, but the problem is that it translates every blob in the Container. This is using:
Uri blobSourceURI = new Uri(“https://” + sAccountName + “.blob.core.windows.net/” + _Containername + “/?” + SASTokenContainer);
I only want to be able to translate only one blob in the container, this is, specifying it, but I always get the same error.
I have searched and re-writen the code many times, using many functions to retrieve the correct SAS token…. thought that maybe the BlobSASToken was no well formed, … but I tryed to copy the direct SAS token (with the correct permissions) from the Azure Explorer…. and It didn’t work either.
Could anybody help me with this? Anybody knows how to fix this?
Many thanks in advance.
Regards
I have tried many functions to retrieve SAS Token. My code:
// Creation of BlobServiceClient
var blobServiceClient = new BlobServiceClient(sConnectionString);
// Container Reference
var containerClient = blobServiceClient.GetBlobContainerClient(sContainerName);
// Blob Reference
var blobClient = containerClient.GetBlobClient(sBlobName);
// Get BlobSAS
BlobSasBuilder sasBuilder = new BlobSasBuilder
{
BlobContainerName = sContainerName,
BlobName = sBlobName,
StartsOn = DateTimeOffset.UtcNow.AddMinutes(-5), // Permiso activo 5 minutos antes de ahora
ExpiresOn = DateTimeOffset.UtcNow.AddHours(1), // La SAS expira en 1 hora
Protocol = SasProtocol.HttpsAndHttp,
Resource = "b"
};
// Assing permissions
sasBuilder.SetPermissions(BlobSasPermissions.Read | BlobSasPermissions.List);
// SAS generation
string sasToken = sasBuilder.ToSasQueryParameters(new Azure.Storage.StorageSharedKeyCredential(blobServiceClient.AccountName, sAccountKey)).ToString();
// complete URI with SAS
Uri blobUriWithSas = new UriBuilder(blobClient.Uri)
{
Query = sasToken
}.Uri;
var client = new DocumentTranslationClient(new Uri(sEndPointTraductorDocumentos), new AzureKeyCredential(sApiKey));
var input = new DocumentTranslationInput(new Uri(blobUriWithSas.AbsoluteUri), sUriFicheroDestino, sIdiomaDestino);
var operation = await client.StartTranslationAsync(input);
await operation.WaitForCompletionAsync(); // ==> HERE IT FAILS