Azure / Azure/azure-functions-java-worker

RpcHttpRequestDataSource cannot be cast to java.lang.String #255

Đang mở
#321 2 bình luận 0 reaction 1 người được giao Được @shreyas-gopalakrishna nhận Xem trên GitHub
area:java-functions needs-investigation reviewed
Ngôn ngữ chính
Java
Star
103
Fork
74
Merge trung bình
4 ngày 8 giờ
Pull request đã merge (30 ngày)
2

Mô tả

This issue is still reproducible for HttpTrigger.

I'm trying to upload a file to azure storage through azure fucntion. I was successful in uploading plain text file but the files are getting corrupted for any other type of files. What I observed is that the bytes that I'm receiving are lesser than the actual size(bodyLength < contentLength).

I tried to change the request data type to HttpRequestMessage>, HttpRequestMessage and Byte[] which is throwing cannot conver to string error as reported in https://github.com/Azure/azure-functions-java-worker/issues/239

@FunctionName("UploadFile")
public HttpResponseMessage run(@HttpTrigger(name = "req", methods = { HttpMethod.GET,
HttpMethod.POST }, authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage> request,
final ExecutionContext context)
throws InvalidKeyException, URISyntaxException, StorageException, IOException {

CloudStorageAccount storageAccount = CloudStorageAccount.parse(_storageConnString);

CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer blobContainer = blobClient.getContainerReference(_containerName);

CloudBlockBlob blob = blobContainer.getBlockBlobReference(fileName);
try {

String body = request.getBody().get();
long bodyLength = body.length();
String contentLength = request.getHeaders().get("content-length");
InputStream inputStream = new ByteArrayInputStream(body.getBytes());
blob.upload(inputStream, Integer.parseInt(bodyLength));

} catch (Exception ex) {
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body(ex.getMessage()).build();
}

return request.createResponseBuilder(HttpStatus.OK).body("File uploaded successfully").build();

}

My requirement is to upload large files to storage. Any help can be appreciated.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.