gpt4 book ai didi

java - 在 azure 服务器中缓慢网络上传视频文件时抛出超时异常

转载 作者:行者123 更新时间:2023-12-02 11:52:22 26 4
gpt4 key购买 nike

我正在尝试在 azure 服务器上上传 10-11 MB 的视频文件。它在 4g 或 wifi 网络上工作正常。但在 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 分割成 block 。如果您未指定值,则默认值为 32 MB,即任何正在上传的文件,如果其大小小于 32 MB,则将上传而不分割为 block 。

由于您提到文件大小为 10-11 MB,小于 32 MB 限制,因此 SDK 正在尝试一次性上传文件。由于互联网连接速度较慢,尝试上传如此庞大的数据的请求超时。

您可以做的是将其值更改为较小的大小。该值应大于 1 MB 但小于 32 MB。然后您的文件将分块上传,您不应该收到此超时错误(希望如此)。要设置该值,您可以添加以下代码行:

uploadOptions.setSingleBlobPutThresholdInBytes(1024*1024);//1MB

关于java - 在 azure 服务器中缓慢网络上传视频文件时抛出超时异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47793540/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com