Upload to ifile.it through Mathematica

后端 未结 2 2078
再見小時候
再見小時候 2020-12-05 08:15

I was wondering whether it\'s possible to upload a file from Mathematica to ifile.it. I have seen the API of ifile.it, however, I still don\'t know how it works. Furthermore

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 09:00

    ragfield's answer gets points for not being a hack, but you can also do this without JLink:

    UploadFile[url_, filePath_, urlParams___] := With[
      {
        bytes = Import[filePath, "Byte"],
        filename = StringJoin[FileBaseName[filePath], ".", FileExtension[filePath]]
      },
      URLExecute[
        url,
        urlParams,
        "Method" -> "POST",
        "MultipartElements" -> {
          {"file\"; filename=\"" <> filename, "application/octet-stream", bytes}
        },
        "Headers" -> {
          "Accept" -> "application/json; charset=UTF-8",
          "Content-Type" -> "multipart/form-data"
        }
      ]
    ]
    

    (Cross-answered from https://mathematica.stackexchange.com/questions/52338/more-complete-mutipartdata-posts-using-urlfetch/97658#97658)

提交回复
热议问题