在缓慢的网络中,在 Azure 服务器中上传视频文件抛出 Timeoutexception
In slow network uploading video file in azure server throwing Timeoutexception
我正在尝试在 azure 上上传 10-11 MB 的视频文件 server.It 在 4g 或 wifi 上工作正常 network.But 它在 3g 或 2g 网络上抛出以下错误。
java.io.IOException: The client could not finish the operation within
specified maximum execution timeout. Please see the cause for further
information..
下面是我的代码:--
try {
// Setup the cloud storage account.
CloudStorageAccount account = CloudStorageAccount
.parse("somestring");
// Create a blob service client
CloudBlobClient blobClient = account.createCloudBlobClient();
BlobRequestOptions uploadOptions = new BlobRequestOptions();
uploadOptions.setMaximumExecutionTimeInMs(300000);
uploadOptions.setTimeoutIntervalInMs(100000);
RetryPolicy retryPolicy=new RetryExponentialRetry(
60000 /* minBackoff in milliseconds */,
30000 /* delatBackoff in milliseconds */,
180000 /* maxBackoff in milliseconds */,
3 /* maxAttempts */);
uploadOptions.setRetryPolicyFactory(retryPolicy);
// Get a reference to a container
// The container name must be lower case
// Append a random UUID to the end of the container name so that
// this sample can be run more than once in quick succession.
CloudBlobContainer container = blobClient.getContainerReference("videos");
// Create the container if it does not exist
container.createIfNotExists();
// Make the container public
// Create a permissions object
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
OperationContext opContext = new OperationContext();
StorageEventMultiCaster storageEventMultiCaster = new StorageEventMultiCaster<>();
// Include public access in the permissions object
containerPermissions
.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
storageEventMultiCaster.addListener(new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
// Do custom monitoring here...
}
});
opContext.setSendingRequestEventHandler(storageEventMultiCaster);
// Set the permissions on the container
container.uploadPermissions(containerPermissions);
CloudBlockBlob blob = container.getBlockBlobReference(file.getName());
byte[] buffer = IOUtils.toByteArray(new FileInputStream(file));
ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer);
blob.upload(inputStream, inputStream.available(),null,uploadOptions,opContext);
inputStream.close();
String url = blob.getUri().toString();
} catch (Throwable t) {
}
我正在使用 com.microsoft.azure.android:azure-storage-android:2.0.0@aar
库。
如有任何帮助,我们将不胜感激。
BlobRequestOptions
有一个名为 singleBlobPutThresholdInBytes
的 属性,它确定在上传时是否应将 blob 分成块。如果您不指定值,默认值为 32 MB
即正在上传的任何文件,如果其大小小于 32 MB,则将不分块上传。
由于您提到文件大小为 10-11 MB
,小于此 32 MB 限制,SDK 正在尝试一次性上传文件。由于 Internet 连接速度较慢,请求在尝试上传如此庞大的数据时超时。
您可以做的是将其值更改为较小的大小。该值应大于 1 MB 但小于 32 MB。然后你的文件将以块的形式上传,你不应该得到这个超时错误(希望如此)。要设置该值,您可以添加以下代码行:
uploadOptions.setSingleBlobPutThresholdInBytes(1024*1024);//1MB
我正在尝试在 azure 上上传 10-11 MB 的视频文件 server.It 在 4g 或 wifi 上工作正常 network.But 它在 3g 或 2g 网络上抛出以下错误。
java.io.IOException: The client could not finish the operation within specified maximum execution timeout. Please see the cause for further information..
下面是我的代码:--
try {
// Setup the cloud storage account.
CloudStorageAccount account = CloudStorageAccount
.parse("somestring");
// Create a blob service client
CloudBlobClient blobClient = account.createCloudBlobClient();
BlobRequestOptions uploadOptions = new BlobRequestOptions();
uploadOptions.setMaximumExecutionTimeInMs(300000);
uploadOptions.setTimeoutIntervalInMs(100000);
RetryPolicy retryPolicy=new RetryExponentialRetry(
60000 /* minBackoff in milliseconds */,
30000 /* delatBackoff in milliseconds */,
180000 /* maxBackoff in milliseconds */,
3 /* maxAttempts */);
uploadOptions.setRetryPolicyFactory(retryPolicy);
// Get a reference to a container
// The container name must be lower case
// Append a random UUID to the end of the container name so that
// this sample can be run more than once in quick succession.
CloudBlobContainer container = blobClient.getContainerReference("videos");
// Create the container if it does not exist
container.createIfNotExists();
// Make the container public
// Create a permissions object
BlobContainerPermissions containerPermissions = new BlobContainerPermissions();
OperationContext opContext = new OperationContext();
StorageEventMultiCaster storageEventMultiCaster = new StorageEventMultiCaster<>();
// Include public access in the permissions object
containerPermissions
.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);
storageEventMultiCaster.addListener(new StorageEvent<SendingRequestEvent>() {
@Override
public void eventOccurred(SendingRequestEvent eventArg) {
// Do custom monitoring here...
}
});
opContext.setSendingRequestEventHandler(storageEventMultiCaster);
// Set the permissions on the container
container.uploadPermissions(containerPermissions);
CloudBlockBlob blob = container.getBlockBlobReference(file.getName());
byte[] buffer = IOUtils.toByteArray(new FileInputStream(file));
ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer);
blob.upload(inputStream, inputStream.available(),null,uploadOptions,opContext);
inputStream.close();
String url = blob.getUri().toString();
} catch (Throwable t) {
}
我正在使用 com.microsoft.azure.android:azure-storage-android:2.0.0@aar
库。
如有任何帮助,我们将不胜感激。
BlobRequestOptions
有一个名为 singleBlobPutThresholdInBytes
的 属性,它确定在上传时是否应将 blob 分成块。如果您不指定值,默认值为 32 MB
即正在上传的任何文件,如果其大小小于 32 MB,则将不分块上传。
由于您提到文件大小为 10-11 MB
,小于此 32 MB 限制,SDK 正在尝试一次性上传文件。由于 Internet 连接速度较慢,请求在尝试上传如此庞大的数据时超时。
您可以做的是将其值更改为较小的大小。该值应大于 1 MB 但小于 32 MB。然后你的文件将以块的形式上传,你不应该得到这个超时错误(希望如此)。要设置该值,您可以添加以下代码行:
uploadOptions.setSingleBlobPutThresholdInBytes(1024*1024);//1MB