Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,25 @@
<version>1.17.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.15</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>

</dependencies>

<build>
<finalName>shared-folder-server</finalName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.Instant;
import java.util.UUID;

@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class FileDto {
public class FileDto implements Serializable {
@JsonProperty("id")
private UUID id;
@JsonProperty("name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;

import java.io.IOException;
import java.util.List;
import java.util.UUID;

Expand All @@ -28,20 +32,22 @@ public ResponseEntity<List<FileDto>> list() {
body(files);
}

@PostMapping
public ResponseEntity<FileDto> create(@Validate(JsonSchema.FILE_CREATE) FileDto fileToAdd) {
log.info("in create, request body: " + fileToAdd);
FileDto addedFile = fileService.create(fileToAdd);
@PostMapping(consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
public ResponseEntity<FileDto> create (@RequestParam("file") MultipartFile file) throws IOException {
FileDto uploadedFile = new FileDto();
uploadedFile.setName(file.getOriginalFilename());
uploadedFile.setContent(file.getBytes());
log.info("in create, request body: " + uploadedFile);
FileDto addedFile = fileService.create(uploadedFile);
return ResponseEntity.status(HttpStatus.CREATED)
.body(addedFile);
}

@GetMapping("{id}")
public ResponseEntity<FileDto> download(@PathVariable UUID id) {
public StreamingResponseBody download(@PathVariable UUID id) {
FileDto file = fileService.findById(id)
.orElseThrow(() -> new FileNotFoundError(id));
return ResponseEntity.status(HttpStatus.OK)
.body(file);
return outputStream -> outputStream.write(file.getContent());
}

@DeleteMapping("{id}")
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ migration:
baselineOnMigration: ${DB_MIGRATION_BASELINE_ENABLED:true}

spring:
servlet:
multipart:
max-file-size: 200MB
max-request-size: 200MB
flyway:
# should be disabled as we use our migration
enabled: false
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"data": null,
"errors": [
{
"name": "ValidationError",
"message": "validation error [$.%fieldName%: %typeName% found, string expected]"
"name": "FileCannotBeCreatedError",
"message": "file could not be created. Illegal file name %fieldName%, file name must be in the form of NAME.KIND, using letters, numbers. some special characters are illegal"
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/cases/file/success-download-file.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"expectedResult": {
"data": {
"kind": "zip",
"content": "QVJsRUFBPT0=",
"content": "ARlEAA==",
"id": "28cbd8e2-4b93-11ed-bdc3-0242ac120002",
"name": "testFile.zip",
"dateModified": 1436224954.000000000,
"dateAdded": 1436224954.000000000,
"size": "4 bytes"
"size": "8 bytes"
}
}
}
2 changes: 1 addition & 1 deletion src/test/resources/cases/file/success-upload-file.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "testFile.zip",
"dateModified": "2022-10-17T08:29:13.096594Z",
"dateAdded": "2022-10-17T08:29:13.096553Z",
"size": "4 bytes"
"size": "8 bytes"
}
}
}