Answer the question
In order to leave comments, you need to log in
How to add an image to an array of images on the server?
Hello! At the moment there is a class that sends from 1 to 11 parameters to the server in JSON format (this is a text parameter and from 0 to 10 NSNumber format parameters). And the class is built in such a way that when you change any format, all data that is already on the server is deleted and new ones are saved, that is, a complete overwrite occurs. It's not scary because the maximum amount of this data is only 2.7 kilobytes. The assignment says "Organize as an array of image links", and that you just need to add an array of images to the current class. But there are several problems: 1 If there is already one image on the server, and we just add another one, then it turns out that two images are being overwritten, but what if there are 10 of them? This is a strong blow to the user's traffic, plus this is not the correct design of the interaction between the server and the application. 2 While overwriting more than 5 images, I get an error that the server is not available. I want to send a specific image to an already existing array of images on the server, and not overwrite them every time. Also assign an ID to each image so that you can delete images from the application on the server. I have tried many different options but could not achieve the desired result. Here is the current class code
public class AnswersDataServerEntity: DataSetEntity {
static let DataSetName = "DataSetName"
var id: String? = "0"
var streetId: UInt = 0
var streetName: String? = ""
var answers: [AnswerServerEntity]? = []
var documents: [DocumentServerEntity]? = []
private func save()
{
let deleteCommand = DataSetCommand(dataSetAction: DeleteDataSetAction<AnswersDataServerEntity>(dataSetName: AnswersDataServerEntity.DataSetName, data: self)
deleteCommand.executeWithSuccess(
{ (commond) -> Void in
self.add()
},
errorHandler: { (error) -> Void in
})
}
private func add()
{
let command = DataSetCommand(dataSetAction: AddDataSetAction<AnswersDataServerEntity>(dataSetName: AnswersDataServerEntity.DataSetName, data: self)
command.executeWithSuccess(
{ (command) -> Void in
if let _command = command as? DataSetCommand<AnswersDataServerEntity> {
NSLog("\(_command.dataSetAction)")
}
},
errorHandler: { (error) -> Void in
})
}
static func saveSelected()
{
self.selected().save()
}
static private func selected() -> AnswersDataServerEntity
{
var result = AnswersDataServerEntity()
if let selectedCountry = CountryEntity.selected(){
for answer in AnswerEntity.userAnswers() {
result.answers?.append(AnswerServerEntity(questionId: answer.questionId))
}
}
for document in DocumentEntity.deserializeDocuments() {
result.documents?.append(DocumentServerEntity(documentId: document.documentId, documentTitle: document.documentTitle, documentImageString: document.documentImageURL))
}
return result
}
}
public class AnswerServerEntity: DataSetEntity {
var questionId: Int = 0
convenience init (questionId: Int){
self.init()
self.questionId = questionId
}
}
public class DocumentServerEntity: DataSetEntity {
var documentId: Int = 0
var documentTitle: String = ""
var documentImageString: String! // this string will to need to decode in base64string that we can to send it as JSON
convenience init(documentId: Int, documentTitle: String, documentImageString: String) {
self.init()
self.documentId = documentId
self.documentTitle = documentTitle
self.documentImageString = documentImageString
}
}
request: {
"object" : "storage",
"section" : "api",
"method" : "addData",
"data" : [
{
"answers" : [
{
"questionId" : 01
},
{
"questionId" : 03
},
{
"questionId" : 06
},
{
"questionId" : 10
}
],
"documents" : [
{
"documentImageString" : "\/var\/mobile\/Containers\/Data\/Application\/DD6F8D10-1241-4119-9639-AB983B27CFA6\/Documents\/04DDA484-F257-43BC-A459-3BC7C6050D6F",
"documentTitle" : "xcode",
"documentId" : 0
}
],
"streetName" : "Молодежная",
"id" : "0",
"streetId" : 14
}
],
"token" : "**********************$$$$*$*$*$",
"dataSet" : "DataSetName"
}
Answer the question
In order to leave comments, you need to log in
Transfer images in turn and append to an array stored in the session?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question