Alamofire multipartFormData.append method raise Fatal error: Call of deleted method - alamofire

I am using Alamofire and I use Alamofire for the http request and uploading image to the server.
Normally, I use simple http request, but today I checked uploading request.
I got the "Fatal error: Call of deleted method" and App was crashed.
This is my code.
Alamofire.upload(multipartFormData: { multipartFormData in
multipartFormData.append(imageData, withName: "image", fileName: "user_image", mimeType: "image/png")
if let params = params {
for (key, value) in params {
// This method raise "Fatal error: Call of deleted method"
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
}
}
}, to: path, encodingCompletion: { result in
})
The next code does not raise the error.
multipartFormData.append(imageData, withName: "image", fileName: "user_image", mimeType: "image/png")
But this code raise the error which said "Fatal error: Call of deleted method".
multipartFormData.append(value.data(using: String.Encoding.utf8)!, withName: key)
Before today, this code did not raise the error.
I tried these.
First, I upgraded Alamofire 4.7.2 to 4.7.3.
But the result was same.
Second, This codes are defined in embedded frameworks, so I copy this method to App code directory.
But the result was same.
Environment
XCode 9.4.1
Carthage 0.30.1 to install Alamofire

I solved this problem.
I reinstalled XCode and Simulator, and fixed the problem.
I referenced these links.
How to Uninstall Xcode on macOS
xcode simulator not coming up - reinstall possible?

Related

Access encodingResult when uploading with Alamofire 5

I'm trying to update my app to Alamofire 5 and having difficulties due to a hack-ish way I'm using it I guess.
Anyhow, I need background uploads and Alamofire is not really designed to do this. Even so, I was using it to create a properly formatted file containing multipart form so I can give it to the OS to upload in the background later.
I'll post the code doing this in Alamofire 4, my question is how can I get the url of the file I was previously getting with encodingResults?
// We're not actually going to upload photo via alamofire. It does not offer support for background uploads.
// Still we can use it to create a request and more importantly properly formatted file containing multipart form
Api.alamofire.upload(
multipartFormData: { multipartFormData in
multipartFormData.append(imageData, withName: "photo[image]", fileName: filename, mimeType: "image/jpg")
},
to: "http://", // if we give it a real url sometimes alamofire will attempt the first upload. I don't want to let it get to our servers but it fails if I feed it ""
usingThreshold: UInt64(0), // force alamofire to always write to file no matter how small the payload is
method: .post,
headers: Api.requestHeaders,
encodingCompletion: { encodingResult in
switch encodingResult {
case .success(let alamofireUploadTask, _, let url):
alamofireUploadTask.suspend()
defer { alamofireUploadTask.cancel() }
if let alamofireUploadFileUrl = url {
// we want to own the multipart file to avoid alamofire deleting it when we tell it to cancel its task
let fileUrl = ourFileUrl
do {
try FileManager.default.copyItem(at: alamofireUploadFileUrl, to: fileUrl)
// use the file we just created for a background upload
} catch {
}
}
case .failure:
// alamofire failed to encode the request file for some reason
}
}
)
Multipart encoding is fully integrated into the now-asynchronous request pipeline in Alamofire 5. That means there's no separate step to use. However, you can use the MultipartFormData type directly, just like you would in the request closure.
let data = MultipartFormData()
data.append(Data(), withName: "dataName")
try data.encode()

Error -32 EPIPE broken pipe

I am doing a post request with ajax that should return a partialview but I always get following error in log:
Connection id "0HL6PHMI6GKUP" communication error.
Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -32 EPIPE broken pipe
When looking at the debug log, I see that it is loading the partialview data but than I get the error.
I can't find anything on the net about the -32 EPIPE error, could someone help me explain what this error means?
Ajax call
$( "#PostForm" ).submit(function( event ) {
//Ajax call
$.ajax({
type: 'POST',
url: "/url/path/CreateBox",
data: {
"id": $("#RackId").val(),
"Name": $("#Name").val()
},
success: function(result){
$("#modal").html(result);
}
});
});
Controller
[HttpPost]
public async Task<IActionResult> CreateBox(int id, string Name)
{
//Get the info of the given ID
Rack rack = await this._rackAccess.GetByIdAsync(id);
if (rack == null)
{
return NotFound();
}
Box box = new Box();
box.Rack = rack;
if (!string.IsNullOrEmpty(Name))
{
box.Name = Name;
var result = await this._boxAccess.InsertAsync(box);
//Returns a list of boxes
return PartialView("Boxes", await this._boxAccess.ToRackListAsync(rack.ID));
}else{
//Returns form again
return PartialView("CreateBox", box);
}
}
Version
Aspnet core: 1.1.0
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0"
"Microsoft.AspNetCore.Hosting": "1.1.0",
Solution can be found on github were I posted the problem aswell:
https://github.com/aspnet/KestrelHttpServer/issues/1978
Answer of halter73 on github:
The "communication error" usually comes in ECONNRESET, EPIPE, and ECANCELED varieties. Which one you get usually just depends on which platform you're running on, but all three generally mean the same thing: that the client closed the connection ungracefully.
I have a theory why this is happening. I think that the page might be getting reloaded mid-xhr causing the xhr to get aborted. This can be fixed by returning false from your jQuery submit callback.
I took all your dependencies and your jQuery snippet and demonstrated how this page reload can cause an EPIPE on linux and an ECANCELED on Windows in a sample repro at https://github.com/halter73/EPIPE. It uses csproj instead of project.json because I don't have an old CLI that supports project.json easily available.
Maybe due to long time processing on server-side,
communication pipe was broken by overtime mechanism.
Wish this is helpful.

Issue using Relay mutations with files

I have an issue using File Mutation with Relay. I am trying to create a mutation using getFiles()
Relay.Store.commitUpdate(
new AddOrderMutation({userId: userId, medications: OrderInputTypeMedication,
userAddressId:userAddressId,files:files}),
{
onSuccess: (response) => OnResponseSuccess(response),
onFailure: (transaction,e) => console.log('transaction',transaction.getError(),'e',e),
},
);
}
I always get an error that said
transaction TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (D:\ReactNative\MedexApp\node_modules\react-native\node_modules\whatwg-fetch\fetch.js:436)
although all other requests are working good. also the same mutation is sent correctly without attaching any files.
this is the array of files ["1489322712989.jpg":{filename:"1489322712989.jpg"
uri:"file:///storage/emulated/0/Pictures/1489322712989.jpg"}]
and It never sends the request through fiddler or caught in the webservice
I wasn't adding to the Files Object (type: 'image/jpg'), so the file Object should be as follows:
file ={
uri: this.state.image.uri,
name: this.state.image.name,
type:'image/jpg'
};

Cannot connect to MobileFirst Server during initialization

I am testing developing a Hybrid application in MobileFirst Studio and want to connect to MobileFirst Server during the app init. I updated main.js file under MF_Project/app/[appNanme]/common/js/main.js init method with the following:
WL.Client.connect({
onSuccess: function() {
WL.Logger.info("onSuccess: connection success");
},
onFailure: function(err) {
WL.Logger.info("onFailure: Exception: " + err);
}
});
I then build the app for Android environment (right click the appName the one under MF_Project and select "Build for Android environment"). Then I ran the app as Android Application in emulator, but the log comes back with error
01-25 16:04:29.364: E/NONE(2755): Invalid invocation of method WL.Client.connect; Invalid value 'undefined' (undefined), expected type 'function'.
01-25 16:04:29.368: E/NONE(2755): Invalid invocation of method WL.Client.connect; Invalid options attribute 'onSuccess'. Invalid invocation of method WL.Client.connect; Invalid value 'undefined' (undefined), expected type 'function'.
Any insight on this would be appreciated.
I have tested the supplied project in MFP 6.3 using a Nexus 5 device running Android 5.0.1.
The application successfully connected to the MFP Server.
In the log I saw the SUCCESSFUL: [object object] message.
[object object] because you did not JSON.stringify the result.
For example: WL.Logger.info("SUCCESSFUL: " + JSON.stringify(response));
I think something is wrong with your generated AVD - try to create a new one, in addition to testing in an actual device.

CakePHP 2.0 + Notice (8): Undefined index: Upload [APP/Controller/UploadsController.php, line 32]

Im using 000webhost as a way to host my portfolio of websites. However Im getting this error thrown in which doesn't happen to me on localhost.
Notice (8): Undefined index: Upload [APP/Controller/UploadsController.php, line 32]
This is the code it seems to be referring to,
public function add() {
$this->render();
if($this->request->is('post')){
$file = $this->request->data['Upload']['file'];
if($this->Upload->save($this->data) && move_uploaded_file($file['tmp_name'],APP.'webroot/files/uploads'.DS.$this->Upload->id.'.mp4'))
{
$this->Session->setFlash('<p class="uploadflash">The upload has been saved</p>', true);
$this->redirect(array('controller'=>'Uploads', 'action' => 'watch', $this->Upload->id));
} else {
$this->Session->setFlash('<p class="loginerror">The upload could not be saved, mp4 files can be saved only.</p>', true);
}
}
}
Any ideas as to why this is happening?
Also in addition my Elements are not showing up on this online hosting either?
I get thrown this error on the page
Element Not Found: Elements/uploads/recentuploads.ctp
Does anyone else seem to have this problem??
Upon further inspection I have found that the server does not allow file upload sizes to exceed 2mb, in this instance PHP throws the error above.