Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [leshan-dev] Upload/browse a file from disk to transfer to device.

Hi Joey,

 

happy new year to you J

 

Maybe you can create a pull request for your code (which I think is an interesting addition to the Standalone Server) so that others can check it out, debug on their own machines and provide some feedback?

 

Regards,

Kai

 

From: leshan-dev-bounces@xxxxxxxxxxx [mailto:leshan-dev-bounces@xxxxxxxxxxx] On Behalf Of Joey Smith
Sent: Friday, December 18, 2015 1:58 AM
To: Leshan Developer Discussions
Subject: [leshan-dev] Upload/browse a file from disk to transfer to device.

 

Hi

 

I added a new construct/button to upload firmware update files on the UI. With the new upload button user can now select a file on the disk to be uploaded to the device. The file is transferred to the device but the contents are not correct. The file is uploaded using "multipart/form-data". I added another else block in ClientServlet.java

 

 else if ("multipart/form-data".equals(contentType)) {
      String content = IOUtils.toString(req.getInputStream(), parameters.get("charset"));
      LwM2mNode node;
  try {
       node = gson.fromJson(content, LwM2mNode.class);
  } catch (JsonSyntaxException e) {
       throw new IllegalArgumentException("unable to parse json to tlv:" + e.getMessage(), e);
  }

 

  return server.send(client, new WriteRequest(Mode.REPLACE, null, target, node), TIMEOUT);

 

 }

 

 

Has anybody tried to upload a file to device ?

 

If instead of upload/browse gui which is using "multipart/form-data", I transfer file in java test code by reading it in to a byte array and then sending it to the device, the content is correct.

We are still in ths POC(Proof Of Concept) stage so I am still using Jetty. Wondering if anybody has tried uploading a file with Jetty ?

 

I also added MultipartConfigElement to ClientServlet.java

 

        clientServletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement(System.getProperty("java.io.tmpdir")));


  @MultipartConfig
  public class ClientServlet extends HttpServlet {


Thanks


Back to the top