2010-09-27 50 views
0

最近我正在使用Facebook應用程序,但無論如何facebook不支持帶$ _FILES的表單文章,所以我無法上傳任何帶有php常規文件上傳的文件系統。 現在我正嘗試使用文件上傳與文件的URL位置上載它在一個新的創建相冊。如何使用form multipart/form-data在Facebook應用程序上傳照片

是否有任何簡單的建議,以便用戶可以使用我的應用程序從他/她的計算機上傳照片?

在此先感謝! phpfarmer

回答

5

我認爲這將幫助你< link>備查遵循這一< link>

+0

該訊息的$ args [ 'Lenna.png'] =「@ /家/壽的字節數組AI/htdocs中/應用/ bemyfans/Lenna.png「;是一個預定義的圖像位置,但我想要使用的東西可以通過使用文件輸入類型從他/她的計算機上傳圖像。 – phpfarmer 2010-09-27 07:55:01

0

終於我的代碼工作,臉譜不服從RFC標準,這會導致混淆

final String BOUNDERY = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f"; 
final String CRLF = "\r\n"; 
StringBuilder sbBody_1 = new StringBuilder(); 
sbBody_1.append("--" + BOUNDERY + CRLF); 
sbBody_1.append("Content-Disposition: form-data; filename=\"source\"" + CRLF); 
sbBody_1.append(CRLF); 
StringBuilder sbBody_2 = new StringBuilder(); 
sbBody_2.append(CRLF + "--" + BOUNDERY + "--"); 
URL url = new URL("https://graph.facebook.com/me/photos?access_token=" + accessToken); 
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
connection.setDoOutput(true); 
connection.setRequestMethod("POST"); 
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDERY); 
connection.setChunkedStreamingMode(0); 
OutputStream out = new BufferedOutputStream(connection.getOutputStream()); 
out.write(sbBody_1.toString().getBytes()); 
out.write(bFile); 
out.write(sbBody_2.toString().getBytes()); 
out.close(); 
BufferedReader bips = new BufferedReader(new InputStreamReader(connection.getInputStream())); 
String temp = null; 
while ((temp = bips.readLine()) != null) { 
    Log.d("fbnb", temp); 
} 
bips.close(); 
connection.disconnect(); 

順便說一下,BFILE是位圖

相關問題