图像没有';在服务器上更改应用程序后,应用程序重新下载时不会更新


Image doesn't update when re-downloaded by app, after changing it on the server

编辑:它确实会更新,但会延迟几个小时。。

另一次编辑

它只发生在我的nexus 4上,我今天在SGS1上测试了它,它正常工作。可能是什么问题?

你可以说它有点复杂,所以仔细阅读:

我有一个应用程序可以将图像上传到网络上(图像可以是任何东西,从用户的设备上)。

我现在为这个结构添加了一个编辑功能,如果用户想更改旧的图像,他也可以上传新的图像。

它确实有效。。我通过浏览器进行了测试,服务器上的图像确实发生了变化。

但另一方面,在应用程序上,由于某种原因,它没有改变(即使服务器上的图像现在已经改变,以前的图像也不存在了)。

就像,它保存在设备的缓存中或其他什么地方。。但是:

我不知道这是怎么发生的,因为每次我调用时,下载图像的功能都会再次出现

这是怎么发生的?

如果有人想要我的ImageDownloader函数(但我百分之百肯定问题不存在):

private Bitmap downloadBitmap(String url) {
            // initilize the default HTTP client object
            final DefaultHttpClient client = new DefaultHttpClient();
            // forming a HttoGet request
            final HttpGet getRequest = new HttpGet(url);
            try {
                HttpResponse response = client.execute(getRequest);
                // check 200 OK for success
                final int statusCode = response.getStatusLine().getStatusCode();
                if (statusCode != HttpStatus.SC_OK) {
                    Log.w("ImageDownloader", "Error " + statusCode
                            + " while retrieving bitmap from " + url);
                    return null;
                }
                final HttpEntity entity = response.getEntity();
                if (entity != null) {
                    InputStream inputStream = null;
                    try {
                        // getting contents from the stream
                        inputStream = entity.getContent();
                        // decoding stream data back into image Bitmap that
                        // android understands
                        final Bitmap bitmap = BitmapFactory
                                .decodeStream(inputStream);
                        return bitmap;
                    } finally {
                        if (inputStream != null) {
                            inputStream.close();
                        }
                        entity.consumeContent();
                    }
                }
            } catch (Exception e) {
                // You Could provide a more explicit error message for
                // IOException
                getRequest.abort();
                Log.e("ImageDownloader", "Something went wrong while"
                        + " retrieving bitmap from " + url + e.toString());
            }
            return null;
        }

我的Edit.php文件更新了数据,包括图像(它有效,经过测试):

<?php 
   //1. create connection
   $connection=mysql_connect("localhost","lalala","lalala");/
   if(!$connection)
   {
       die("database connection failed:" . mysql_error());
   }
   $db=mysql_select_db("lalala",$connection);
   if(!db)
   {
              die("database connection failed:" . mysql_error());
   }
   mysql_query("SET NAMES 'utf8'",$connection);

    if ($_POST["lala"]!=null)
   {
    if ($_POST["lalala"]!=null && $_POST["lalala"]!=null)
   {
    $sql="UPDATE `lalala`.`lalal` SET `xxx` = '".$_POST[xxx]."', `xxx`='".$_POST[xxx]."', `xxx` = '".$_POST[xxx]."', `xxx`='".$_POST[xxx]."', `xxxt`='".$_POST[xxx]."', `xxx`= '".$_POST[xxx]."', `xxx` = '".$_POST[xxx]."'  WHERE `xxx`.`xx` = ".$_POST[xx].";";
        $result=mysql_query($sql,$connection);
        if(!$result)
        {
            echo "error.";
            //echo "('".mysql_insert_id($connection)."','".$_POST[title]."','".$_POST[snippet]."','".$_POST[cat]."','".$_POST[desc]."','".$_POST[lat]."','".$_POST[lon]."','".$_POST[pub]."','0','0','".$_POST[program]."','".$_POST[addr]."')'n";
            die("database connection failed:" . mysql_error());
        }
        else {
                if ($_POST[isnewimg]==1)
                {
                    if (unlink("upload/id".$_POST[id].".jpg"))
                    {
                    $target = "upload/";
                    $target = $target . basename( $_FILES['uploaded']['name'].$_POST[id].".jpg");
                    if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
                     {
                        echo "1";
                     }
                    else {echo "Img update failed".$_POST[id];}
                    }
                    else {echo "Img deletion failed".$_POST[id];}
                }
                else
                    echo "1"."w/o image. updated ".$_POST[id];
            }

   }
   }

else {
echo "2";
}
mysql_close($connection);
?> 

如果服务器正在缓存映像,请尝试重置它以确认这是真正的问题。

在客户端:

如果您正在从URL加载图像,例如:

http://ejemplo.com/imagen.png

您可以为每个请求生成一个id,并将其添加到URL中,如下所示:

http://ejemplo.com/imagen.png?request_id=5385683

我不知道你在哪个平台上工作,但这在浏览器中有效。