-
Notifications
You must be signed in to change notification settings - Fork 9
/
HttpTriggerBlobOutput.java
66 lines (59 loc) · 2.43 KB
/
HttpTriggerBlobOutput.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
59
60
61
62
63
64
65
66
package com.danielrocks.function.blob.output;
import java.nio.charset.StandardCharsets;
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.OutputBinding;
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.functions.annotation.BlobInput;
import com.microsoft.azure.functions.annotation.BlobOutput;
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, BlobInput, and BlobOutput.
*
* 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[].
*
* The BlobOutput annotation binds to OutputBinding, which is then used
* by the function to write the contents of the input file to a
* file in the 'samples-workitems-outputs' storage container.
*
*/
public class HttpTriggerBlobOutput {
@FunctionName("copyBlobHttp")
@StorageAccount("Storage_Account_Connection_String")
public HttpResponseMessage copyBlobHttp(
@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,
@BlobOutput(
name = "target",
path = "samples-workitems-outputs/{Query.file}-CopyViaHttp")
OutputBinding<String> outputItem,
final ExecutionContext context) {
// Save blob to outputItem
outputItem.setValue(new String(content, StandardCharsets.UTF_8));
//create response body with size of requested blob
String fileName = request.getQueryParameters().get("file");
String body = "The size of \"" + fileName + "\" is: " + content.length + " bytes. \n";
// do HTTP response
return request.createResponseBuilder(HttpStatus.OK)
.body(body)
.build();
}
}