0

我正在尝试为现有文件创建共享。

当我尝试读取结果时总是出现错误 400 (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));)

任何帮助,将不胜感激

谢谢

    String fileId = uploadFile(token,parentId,baos,fileName,fileData.length);
    
    URL url = new URL(String.format("https://%s/sf/v3/Shares/Send", ShareFileUploader.getHostname(token)));
    connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("POST");
    ShareFileUploader.addAuthorizationHeader(connection, token);
    connection.addRequestProperty("Content-Type", "application/json");
    connection.setDoOutput(true);
    
    connection.connect();
    
    Map<String, Object> share = new HashMap<String, Object>();
    share.put("Items",String.format("[\"%s\"]",fileId));
    share.put("Emails","[ \"user@email.com\"]");
    share.put("RequireLogin", false);
    share.put("RequireUserInfo", false);
    share.put("ExpirationDays", 2);
    share.put("MaxDownloads", 2);
    share.put("SendAnon", true);
    share.put("UsesStreamIDs", false);
    share.put("Subject","File");
    share.put("Body","New file");
    
    Gson gson = new Gson();
    String body = gson.toJson(share);
    
    connection.getOutputStream().write(body.getBytes());

BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

也试过

String fileId = uploadFile(token,parentId,baos,fileName,fileData.length);

URL url = new URL(String.format("https://%s/sf/v3/Shares?notify=false", getHostname(token)));
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
ShareFileUploader.addAuthorizationHeader(connection, token);
connection.addRequestProperty("Content-Type", "application/json");
connection.setDoOutput(true);

connection.connect();

Map<String, Object> share = new HashMap<String, Object>();
share.put("ShareType", "Send");
share.put("Items",String.format("[{ \"Id\":\"%s\" }]",fileId));
share.put("Recipients","[{ \"User\": { \"Email\": \\\"user@email.com\\\" } } ]");
share.put("ExpirationDate","\""+ sdf.format(new Date(System.currentTimeMillis()+(1000*60*60*24*7)))+"\"");
share.put("Parent", String.format("[{ \"Id\":\"%s\" }]",parentId));
share.put("RequireLogin", false);
share.put("RequireUserInfo", false);
share.put("MaxDownloads", 2);
share.put("Title", true);
share.put("UsesStreamIDs", false);

Gson gson = new Gson();
String body = gson.toJson(share);

connection.getOutputStream().write(body.getBytes());

BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); 
4

0 回答 0