Hi, @nikolay.khoroshevski
Since version 1.1 files could be uploaded using endpoint /graphql/files
.
For example using httpie
http POST http://localhost:8080/graphql/files @/Pictures/1.png "Authorization: Bearer $AUTH_TOKEN"
Response will looks like
{
"fileRef": "fs://2022/02/02/ef12d68f-5a04-f6d2-e3ba-187ffe8b19f5?name=",
"name": "",
"size": 7778
}
at this point the file is already saved on the server.
Response contains FileRef
string representation of saved file.
Then file ref could be send on server as part of dto via custom mutation. In custom mutation method on back end string representation could be converted to object of FileRef
class using FileRef::fromString
method.
@JmixEntity(name = "petclinic_PetDto")
public class PetDto {
@JmixGeneratedValue
@JmixId
@JmixProperty(mandatory = true)
private UUID id;
@JmixProperty
private String photoFileRef;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public String getPhotoFileRef() {
return photoFileRef;
}
public void setPhotoFileRef(String photoFileRef) {
this.photoFileRef = photoFileRef;
}
}
@Service
@GraphQLApi
public class PetDtoService {
@GraphQLMutation
public PetDto createPetDto(PetDto petDto) {
FileRef photoFile = FileRef.fromString(petDto.getPhotoFileRef());
System.out.println("photoFile = " + photoFile);
return petDto;
}
}
Full example could be found at graphql-file-upload-example branch in jmix-petclinic example app.