-
Notifications
You must be signed in to change notification settings - Fork 9
/
HttpTriggerBlobInput.java
58 lines (49 loc) · 2.07 KB
/
HttpTriggerBlobInput.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.danielrocks.function.blob.input;
import java.util.Optional;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.HttpMethod;
import com.microsoft.azure.functions.HttpRequestMessage;
import com.microsoft.azure.functions.HttpResponseMessage;
import com.microsoft.azure.functions.HttpStatus;
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.functions.annotation.BlobInput;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.HttpTrigger;
import com.microsoft.azure.functions.annotation.StorageAccount;
/**
* Azure Function with HttpTrigger and BlobInput.
*
* The following example shows a Java function that uses the HttpTrigger
* annotation to receive a parameter containing the name of a file
* in a blob storage container. The BlobInput annotation then reads the file
* and passes its contents to the function as a byte[].
*
*/
/*
* Provided that you've set up your local environment with the setupenvironment.ps1 script, you can try it out using http://localhost:7071/api/getBlobSizeHttp?file=testdata.txt
*/
public class HttpTriggerBlobInput {
@FunctionName("getBlobSizeHttp")
@StorageAccount("Storage_Account_Connection_String")
public HttpResponseMessage blobSize(
@HttpTrigger(name = "req",
methods = {HttpMethod.GET},
authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage<Optional<String>> request,
@BlobInput(
name = "file",
dataType = "binary",
path = "samples-workitems/{Query.file}")
byte[] content,
final ExecutionContext context) {
//extract information about the requested blob
String filename = request.getQueryParameters().get("file");
Integer fileLength = content.length;
//Construct a body for the response
String body = "The size of \"" + filename + "\" is: " + fileLength + " bytes";
// build HTTP response
return request.createResponseBuilder(HttpStatus.OK)
.body(body)
.build();
}
}