Answer the question
In order to leave comments, you need to log in
How to write a function to get a list of multiple/single files attached to an email in android retrofit?
In my application, I work with messages that come to me in one service. Each email may or may not have an attached file that the user wants to download. For downloading, they gave me api, for a start, here is the api itself:
URL
id - message id for view INT
attach_file_name - name of attached file
https://сервер/v1/message/<id>/attachment/<attach_file_name>
Method
GET
URL Params
type
0 - for received messages
1 - for sent messages
Data Params
{}
Success Response
HTTP 200
Headers:
Content-Type: TYPE # file mimetype
Content-Disposition: attachment; filename=FILENAME # attached file name
Body: file
Sample Call
curl -i -X GET -H "Content-Type:application/json" -H "Authorization:Bearer $ACCESS_TOKEN" https://сервер/v1/message/ID/attachment/ATTACH_FILE_NAME?type=TYPE
"attach":
public class ViewMessage {
@SerializedName("date")
@Expose
private String date;
@SerializedName("type")
@Expose
private String type;
@SerializedName("user_id")
@Expose
private String userId;
@SerializedName("body")
@Expose
private String body;
@SerializedName("can_delete")
@Expose
private String canDelete;
@SerializedName("can_reply")
@Expose
private String canReply;
@SerializedName("name")
@Expose
private String name;
@SerializedName("subject")
@Expose
private String subject;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
/*public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}*/
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getCanDelete() {
return canDelete;
}
/*public void setCanDelete(String canDelete) {
this.canDelete = canDelete;
}*/
public String getCanReply() {
return canReply;
}
/*public void setCanReply(String canReply) {
this.canReply = canReply;
}*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSubject() {
return subject;
}
/*public void setSubject(String subject) {
this.subject = subject;
}*/
}
Answer the question
In order to leave comments, you need to log in
Work like an array of arrays. Create a variable
@SerializedName("attach")
private String[][] attach;
attach[0][0] // имя
attach[0][1] // размер. если нужно, приводите ко float
// и тд
private class FileData{
private String name;
private float size;
}
@SerializedName("attach")
private FileData[] attach;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question