简体   繁体   中英

500 Internal Server Error on uploading the image

I'm facing an issue to uploading an image to server. and getting 500 Internal Server Error .

I'm uploading the image by below code

ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
    [request setRequestMethod:@"PUT"];
    [request setPostValue:[[NSUserDefaults standardUserDefaults]valueForKey:@"nickname"] forKey:@"nick"];

    NSData *imageData = UIImagePNGRepresentation(img.image);
     [request addData:imageData withFileName:@"image.png" andContentType:@"image/png" forKey:@"image"];
    //[request setData:imageData withFileName:@"profileImage.jpeg" andContentType:@"image/jpeg" forKey:@"image"];

    [request setDelegate:self];
    [request setDidFinishSelector:@selector(requestSuccess:)];
    [request setDidFailSelector:@selector(requestFailed:)];
    [request startAsynchronous];

and in response

-(void)requestSuccess:(ASIFormDataRequest *)request{
    NSLog(@"%@",[request responseData]);
    NSError *error;

    NSString* newStr = [[[NSString alloc] initWithData:[request responseData]
                                          encoding:NSUTF8StringEncoding] autorelease];
    NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:[request responseData] options:NSJSONReadingAllowFragments error:&error];

    NSLog(@"%@",error);
}

firstly there is an error on converting data JSON data to NSdictionary , and it through below error

 Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x8563f70 {NSDebugDescription=Invalid value around character 0.}

then I tried to check be converting Response data in nsstring as done above and by doing so I'm getting below string in response

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
 <title>500 Internal Server Error</title>
 <h1>Internal Server Error</h1>
 <p>The server encountered an internal error and was unable to complete your request.    Either the server is overloaded or there is an error in the application.</p>

what can be the issue?

This:

[request setRequestMethod:@"PUT"];

Should be:

[request setRequestMethod:@"POST"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM