2017-05-25 58 views
-2

我试图从存储器上传映像到服务器。我在这里做错了什么?我需要为此使用PHP脚本吗?无法使用快速Android网络库将映像上载到服务器

私有类UploadImage扩展的AsyncTask {

File picPath; 
    String picName; 

    public UploadImage(File picPath, String picName){ 
     this.picPath= picPath; 
     this.picName = picName; 
    } 

    @Override 
    protected Void doInBackground(Void... params) { 
     String uril = getResources().getString(R.string.ServerPath) + "MyFiles/" + picName; 
     AndroidNetworking.upload(uril) 
       .addMultipartFile(picName, picPath) 
       .addMultipartParameter("key","value") 
       .setPriority(Priority.MEDIUM) 
       .build() 
       .setUploadProgressListener(new UploadProgressListener() { 
        @Override 
        public void onProgress(long bytesUploaded, long totalBytes) { 
         if (bytesUploaded == totalBytes){ 
          Toast.makeText(getApplicationContext(), "Image Uploaded!",Toast.LENGTH_SHORT).show(); 
         } 

        } 
       }); 

     return null; 
    } 

    @Override 
    protected void onPostExecute(Void aVoid) { 
     super.onPostExecute(aVoid); 
     Toast.makeText(getApplicationContext(), "Uploaded!",Toast.LENGTH_SHORT).show(); 

    } 
} 

回答

0

如果你想上传图片到PHP服务器,那么你必须使用PHP代码。在this例子,它说明如何出现在库应用程序上传图片到PHP服务器

0

请注意,你必须考虑载为POST库,但如果你需要使用“把”方法的API调用将失败,为你提供400个不好的请求。

相关问题