mirror of
https://github.com/BgaSol/sol-cloud
synced 2026-05-23 17:18:44 +00:00
feat(model-file): Add FileCreateDto constructor
This commit is contained in:
parent
b39ce418e9
commit
be08569228
1 changed files with 54 additions and 1 deletions
|
|
@ -4,10 +4,17 @@ import com.bgasol.common.core.base.dto.BaseCreateDto;
|
|||
import com.bgasol.model.file.file.entity.FileEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.*;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@SuperBuilder
|
||||
|
|
@ -22,4 +29,50 @@ public class FileCreateDto extends BaseCreateDto<FileEntity> {
|
|||
public FileEntity toEntity() {
|
||||
throw new UnsupportedOperationException("方法未实现");
|
||||
}
|
||||
|
||||
public FileCreateDto(String fileName, byte[] bytes, String mediaType) {
|
||||
super();
|
||||
this.uploadFile = new MultipartFile() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOriginalFilename() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContentType() {
|
||||
return mediaType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return bytes.length == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
return bytes.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBytes() throws IOException {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return new ByteArrayResource(bytes).getInputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transferTo(File dest) throws IllegalStateException {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue