Skip to content

Instantly share code, notes, and snippets.

@Gogetter
Last active August 1, 2021 07:01
Show Gist options
  • Save Gogetter/702aacdbcf4f56f617c7904d36504727 to your computer and use it in GitHub Desktop.
Save Gogetter/702aacdbcf4f56f617c7904d36504727 to your computer and use it in GitHub Desktop.
Http trigger function with Blob input
@FunctionName("download")
@StorageAccount("<STORAGE-ACCOUNT-NAME-FROM-THIS-DEPLOYED-FUNCTION")
public HttpResponseMessage downloadFile(
@HttpTrigger(
name = "req",
methods = {HttpMethod.GET},
authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage<Optional<String>> request,
@BlobInput(
name = "filename",
dataType = "binary",
path = "java-functions-container/{filename}",
connection = "AzureWebJobsStorage")
byte[] content,
final ExecutionContext context) {
context.getLogger().info("FileDownloadHttpTrigger processed a request.");
if (content != null && content.length > 0) {
return request.createResponseBuilder(HttpStatus.OK)
.body(content)
.build();
} else {
return request.createResponseBuilder(HttpStatus.BAD_REQUEST)
.body("The searched file does not exist.")
.build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment