简体   繁体   English

防止请求超时-大POST数据

[英]Prevent request timing out - large POST data

In my iOS app, to post a new question, I make a HTTP POST request to http://api.mysite.com/questions . 在我的iOS应用中,要发布新问题,我向http://api.mysite.com/questions发出了HTTP POST请求。 The POST data is obviously larger or smaller depending on whether an image is attached to the question or not. POST数据明显更大或更小,具体取决于是否将图像附加到问题上。 Small (sized around 100-200kb) images are POSTed to the server without a problem. 小型(大小约为100-200kb)的映像可以无问题地发布到服务器。 However, larger photos (~1mb), from the device's camera cause the request to time out due to the large size of the image. 但是,由于图像较大,来自设备相机的较大照片(〜1mb)会导致请求超时。

Please can you tell me how I can make sure that the image is uploaded without a problem, this doesn't seem to happen for many other apps. 请您告诉我如何确保上传的图像没有问题,其他许多应用程序似乎都不会发生这种情况。

Is it a problem with the server or with the iOS code itself? 服务器或iOS代码本身有问题吗?

Edit---- 编辑 - -

On the server, once the request has been received, the PHP just writes the image data to a file. 在服务器上,一旦收到请求,PHP便将图像数据写入文件。 The blob is the image data: 斑点是图像数据:

$filepath = $this->debug == true ? "../cityw/img/questions/{$qid}/attachment.png" :"../i/questions/$qid/attachment.png";

if (!file_exists($this->debug == true ? "../cityw/img/questions/{$qid}" : "../i/questions/{$qid}")) {
    mkdir($this->debug == true ? "../cityw/img/questions/{$qid}" : "../i/questions/{$qid}");
}

$fh = fopen($filepath, 'w');

fwrite($fh, $blob);
fclose($fh);

The image data is sent to the server in BASE64, and then decoded once it has reached the server. 图像数据在BASE64中发送到服务器,然后在到达服务器后解码。

Have you tried fixing your problem with set_time_limit 您是否尝试过解决set_time_limit的问题

Glad that worked out for you. 很高兴为您解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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