How to send image data to server? (I already have a sample page)

我的梦境 提交于 2019-12-12 05:08:56

问题


How to send image data to server? (I already have a sample page)

Sample Page html Source Code

<form action="/uploadfile.html" method="post"
    enctype="multipart/form-data" onSubmit="return validate();">

    <fieldset><legend>Upload File</legend>
    <table>
        <tr>
            <td><input name="fileData" id="image" type="file" /></td>
        </tr>
        <tr>
            <td><br />
            </td>
            <td><input type="submit" value="Upload" /></td>
        </tr>
    </table>
    </fieldset>
</form>

It works fine on web page. (File Name: 1234.png) This server check file name and save specific DB.

Example (These work very well on web page *http://SAMPLE_PAGE.com/uploadfile.html*)

1234.png or 5678.png =upload=> save to number.db
abcd.png or wxyz.png =upload=> save to alphabet.db

I must upload via iOS and I have a data object (imgData).

NSData *imgData; //  Image Data
NSString *wantedFileName = @"1234.png";

How to upload to server via iOS Device? (like sample web-page)


回答1:


When we want to upload any file on server using some application we can use multi-part request for this. In this we create a NSURLMutableRequest object with multipart body having desired data.

You can visit following links for a pointer: send image to server in multipart iphone

Sending multipart request from iPhone to Ruby on Rails (RoR) server



来源:https://stackoverflow.com/questions/9477046/how-to-send-image-data-to-server-i-already-have-a-sample-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!