how to upload image dynamically on server?

后端 未结 2 909
-上瘾入骨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: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

提交回复
热议问题