Skip to content

Instantly share code, notes, and snippets.

@PostMapping(value = ["uploadFile"], produces =[APPLICATION_JSON_VALUE])
fun uploadFile(@RequestParam file: MultipartFile, @RequestParam uploadBy: String):ResponseEntity<String>{
val filename = file.originalFilename
val uploadBy = uploadBy
require(filename != null) {"File Must be Selected"}
val hash: SecureHash = if(!(file.contentType == "zip")){
upload(file.inputStream, uploadBy,filename!!)
}else{
proxy.uploadAttachmentWithMetadata(
jar = file.inputStream,
@Webmobsoft
Webmobsoft / download_using_name.kt
Created June 28, 2019 06:41
Download Attachemnt using Name
@GetMapping(value = ["downloadFileByName"], produces = [APPLICATION_JSON_VALUE])
fun downloadFileByName(@RequestParam name:String):ResponseEntity<Resource>{
val attachmentIds: List<AttachmentId> = proxy.queryAttachments(
AttachmentQueryCriteria.AttachmentsQueryCriteria(filenameCondition =
Builder.equal(name)),
null
)
val inputStreams = attachmentIds.map { proxy.openAttachment(it) }
val zipToReturn = inputStreams.single()
return ResponseEntity.ok().header(
@Webmobsoft
Webmobsoft / download_using_hash.kt
Created June 28, 2019 06:39
Download Using Hash
@GetMapping(value = ["downloadFile/{hash}"], produces = [APPLICATION_JSON_VALUE])
fun downloadFileByHash(@PathVariable hash:String):ResponseEntity<Resource>{
val inputStream = InputStreamResource(proxy.openAttachment(SecureHash.parse(hash)))
return ResponseEntity.ok().header(
HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename=\"$hash.zip\""
).body(inputStream)
}
@Webmobsoft
Webmobsoft / upload_attachement.kt
Created June 28, 2019 06:35
Upload Attachement on Corda Ledger
@PostMapping(value = ["uploadFile"], produces =[APPLICATION_JSON_VALUE])
fun uploadFile(@RequestParam file: MultipartFile, @RequestParam uploader: String):ResponseEntity<String>{
val filename = file.originalFilename
val uploader = uploader
require(filename != null) {"File Name must be set"}
val hash: SecureHash = if(!(file.contentType == "zip" || file.contentType == "jar")){
uploadZip(file.inputStream, uploader,filename!!)
}else{
proxy.uploadAttachmentWithMetadata(
jar = file.inputStream,