GithubHelp home page GithubHelp logo

Comments (12)

jefft0 avatar jefft0 commented on June 2, 2024

Hello @zhangchengtest . This command doesn't read the file from the file system. It is read from the body of the request. Have you tried one of the "body" methods?

// Body methods
/**
* Adds an InputStream body to the request.
*
* @param body The InputStream from which to read the body
* @return This instance of RequestBuilder
* @see <a href="https://docs.ipfs.io/reference/api/http/">IPFS API Doc</a>
*/
public RequestBuilder withBody(@NonNull InputStream body) {
Objects.requireNonNull(body, "body should not be null");
requestBuilder.body(new InputStreamToGo(body));
return this;
}
/**
* Adds a string body to the request.
*
* @param body The string value of the body to add
* @return This instance of RequestBuilder
* @see <a href="https://docs.ipfs.io/reference/api/http/">IPFS API Doc</a>
*/
public RequestBuilder withBody(@NonNull String body) {
Objects.requireNonNull(body, "body should not be null");
requestBuilder.bodyString(body);
return this;
}
/**
* Adds a byte array body to the request.
*
* @param body The byte array value of the body to add
* @return This instance of RequestBuilder
* @see <a href="https://docs.ipfs.io/reference/api/http/">IPFS API Doc</a>
*/
public RequestBuilder withBody(@NonNull byte[] body) {
Objects.requireNonNull(body, "body should not be null");
requestBuilder.bodyBytes(body);
return this;
}
/**
* Adds a file as a body to the request.
*
* @param body The file to add as a body
* @return This instance of RequestBuilder
* @throws FileNotFoundException If the file is inaccessible
* @see <a href="https://docs.ipfs.io/reference/api/http/">IPFS API Doc</a>
*/
public RequestBuilder withBody(@NonNull File body) throws FileNotFoundException {
Objects.requireNonNull(body, "body should not be null");
FileInputStream fis = new FileInputStream(body);
requestBuilder.fileBody(body.getName(), new InputStreamToGo(fis));
return this;
}

from gomobile-ipfs.

zhangchengtest avatar zhangchengtest commented on June 2, 2024

Hi, I use the method withBody like this

File file = new File(Environment.getExternalStorageDirectory(), fileName);
InputStream inputStream = ipfs.newRequest("add").withBody(file).send();

But I got anthor error

go.Universe$proxyerror: read unix @->//data/user/0/com.cunw.peer/cache/sock/0000000: use of closed network connection

from gomobile-ipfs.

jefft0 avatar jefft0 commented on June 2, 2024

What is your test setup? Are you using an Android simulator, or connected to a real phone? Before trying new commands, do the test commands work? For example, in the packages directory:

make test_bridge.android

from gomobile-ipfs.

zhangchengtest avatar zhangchengtest commented on June 2, 2024

I use a real phone and there is another error when I use another file

go.Universe$proxyerror: Post "http://unix/api/v0/add?": EOF

from gomobile-ipfs.

jefft0 avatar jefft0 commented on June 2, 2024

We need to know if basic IPFS is working. Does make test_bridge.android work?

from gomobile-ipfs.

zhangchengtest avatar zhangchengtest commented on June 2, 2024

not try this, but i will try later.
but I have tried a lot command like ipfs get , ipfs swam peers...
they all works in the app installed in my phone
only the "add" not work

from gomobile-ipfs.

zhangchengtest avatar zhangchengtest commented on June 2, 2024

make test_bridge.android have no problem

from gomobile-ipfs.

zhangchengtest avatar zhangchengtest commented on June 2, 2024

follow the example it is ok. but I got the cid not same as the cid where I add the same file to computer.
`
ByteArrayOutputStream outputStream = new ByteArrayOutputStream( );
outputStream.write("--------------------------5f505897199c8c52\r\n".getBytes());
outputStream.write("Content-Disposition: form-data; name="file"\r\n".getBytes());
outputStream.write("Content-Type: application/octet-stream\r\n\r\n".getBytes());
outputStream.write(buffer.toByteArray());
outputStream.write("\r\n\r\n--------------------------5f505897199c8c52--".getBytes());

byte body[] = outputStream.toByteArray();

ArrayList jsonList = ipfs.newRequest("add")
.withHeader("Content-Type", "multipart/form-data; boundary=------------------------5f505897199c8c52")
.withBody(body)
.sendToJSONList();

String cid = jsonList.get(0).getString("Hash");
Log.d(TAG, "cid is " + cid);

from gomobile-ipfs.

zhangchengtest avatar zhangchengtest commented on June 2, 2024

witbody bytes function works, but inputstream not work
always throw the EOF exception in InputStreamToGo

from gomobile-ipfs.

jefft0 avatar jefft0 commented on June 2, 2024

Hello @zhangchengtest . Thank you for testing. I have reproduced your error and I created a bug report. We will look into it.
#143

from gomobile-ipfs.

jefft0 avatar jefft0 commented on June 2, 2024

Hello @zhangchengtest . We merged pull request #146 to fix the EOF exception in InputStreamToGo . This test of the API now works.

Does this resolve your issue?

from gomobile-ipfs.

jefft0 avatar jefft0 commented on June 2, 2024

Bug was fixed. This issue is inactive. Presumed resolved. Closing.

from gomobile-ipfs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.