how to upload image dynamically on server?

后端 未结 2 910
-上瘾入骨i
-上瘾入骨i 2021-01-16 07:21

In my application i want to upload the images to server.

I am able to upload images on server but the name of the image mention in front of filename=%@.jpg. remains

相关标签:
2条回答
  • 2021-01-16 07:43

    this line [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];

    Content-Type: image/jpeg

    instead of Content-Disposition: form-data

    and learn how to use content type

    0 讨论(0)
  • 2021-01-16 07:58

    change

    [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    

    to

     [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.jpg\"\r\n",filename] dataUsingEncoding:NSUTF8StringEncoding]];
    

    where filename is a NSString* variable with your desired filename

    0 讨论(0)
提交回复
热议问题