[英]Not able to read file uploaded into Azure Blob
嘗試使用startCopy()將文檔從公共URL上傳到Blob時無法上傳文件的內容
使用uploadFromFile(filePath)上傳相同的url
非工作代碼
URL url =new URL ("http://irpages2.equitystory.com/download/companies/douglasgmbh/Pres_web/6M_FY2018-19_InvestorUpdate.pdf");
newBlobReference.startCopy(new URI(url.toString()));
工作代碼
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
try (ReadableByteChannel rbc = Channels.newChannel(conn.getInputStream());
final FileOutputStream fos = new FileOutputStream(filePath)) {
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
}
newBlobReference.uploadFromFile(filePath);
想要上傳文件而不必先在本地系統上下載,因為這需要大量文件的時間。 其次,即使容器中存在blob,也無法讀取使用startCopy()下載的URL
我嘗試使用startCopy
並獲得與您相同的結果,該文件沒有內容。 我不知道原因所以我使用BlobOutputStream
上傳文件並且工作正常。下面是我的代碼,你可以嘗試一下。
String connectionString = String.format("DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=%s", ACCOUNT_NAME, ACCOUNT_KEY);
CloudStorageAccount account = CloudStorageAccount.parse(connectionString);
CloudBlobContainer container = null;
CloudBlobClient client = account.createCloudBlobClient();
container = client.getContainerReference("blobcontainer");
CloudBlockBlob blob = container.getBlockBlobReference("6M_FY2018-19_InvestorUpdate.pdf");
URL uri =new URL("http://irpages2.equitystory.com/download/companies/douglasgmbh/Pres_web/6M_FY2018-19_InvestorUpdate.pdf");
InputStream is=uri.openStream();
BlobOutputStream blobOutputStream = blob.openOutputStream();
int next = is.read();
while (next != -1) {
blobOutputStream.write(next);
next = is.read();
}
blobOutputStream.close();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.