This repository has been archived by the owner on Sep 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added multipart files uploads endpoint (#41)
* added multipart files uploads endpoint * added 3 tests
- Loading branch information
Showing
11 changed files
with
219 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/com/github/estuaryoss/agent/service/StorageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.github.estuaryoss.agent.service; | ||
|
||
import org.apache.commons.compress.utils.IOUtils; | ||
import org.springframework.core.io.ByteArrayResource; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import javax.validation.Valid; | ||
import java.io.*; | ||
|
||
@Service | ||
public class StorageService { | ||
|
||
public void store(@Valid byte[] content, String filePath) throws IOException { | ||
try (OutputStream outputStream = new FileOutputStream(filePath)) { | ||
org.apache.commons.io.IOUtils.write(content, outputStream); | ||
} | ||
} | ||
|
||
public void store(MultipartFile file, String filePath) throws IOException { | ||
store(file.getBytes(), filePath); | ||
} | ||
|
||
public ByteArrayResource loadAsResource(String filePath) throws IOException { | ||
ByteArrayResource resource; | ||
try (InputStream in = new FileInputStream(filePath)) { | ||
resource = new ByteArrayResource(IOUtils.toByteArray(in)); | ||
} | ||
return resource; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.