0

I'm using milton, and my upload code as follows:

@PutChild 
@Transactional 
public FileContentItem uploadFile(FolderContentItem parent, String name, byte[] bytes){
 String traceId = UuidGenUtil.createUuid();
 try { 
     QUERY_LOGGER.info("[uploadFile][NetdiskController],action=Request, name={}, size={},traceId={}",name,bytes.length,traceId);

In windows, i can upload file successfully, but with Mac Finder, the length of bytes is always 0, and the error as follow:

The Finder can't complete the operation because some data in "Shot.png" can't be read or written (Error code -36)

Anyone know why? Thanks

Update: I try ForkLift webdav client in mac and can upload file successfully

chou
  • 344
  • 3
  • 17

1 Answers1

0

The problem is that mac finder sends first request for creating new file without any byte

After it - call LOCK, which is not available for Dav Level 1, that's why you have bad response from server and mac stop uploading a file. This method availiable only for Dav level 2, so you have to get enterprise license of milton to make it work

After Locking object Finder uploads the file

After - calls UNLOCK method

SO if you want to use mac finder for webdav in milton you have several options:

  1. Get the trial enterprise license and look into this example:https://github.com/miltonio/milton2/tree/master/examples/milton-anno-ref

  2. Realize these methods by yourself by webdav specs

  3. Mock it - extend from MiltonFilter or look into MyOwnServlet in example and in method doFilter/service write something like this:

    //mock method, do not use it in production!
    HttpServletRequest request = (HttpServletRequest)req;
    HttpServletResponse response = (HttpServletResponse) resp;
    if(request.getMethod().equals("LOCK")){
        response.setStatus(200);
        response.addHeader("Lock-Token", "<opaquelocktoken:e71d4fae-5dec-22d6-fea5-00a0c91e6be4>");
    } else if(request.getMethod().equals("UNLOCK")){
        response.setStatus(204);
    }else {
        doMiltonProcessing((HttpServletRequest) req, (HttpServletResponse) resp);
    }
    

I've checked this code working in the examble by link above: make in web.xml method serving by MyOwnServlet, disable authentication in init by implementing empty security manager, set controller packages to scan "com.mycompany"

p.s. to build the example project I've to delete milton client dependency from pom.xml file

  • Thanks, but it seems some address(like register trial enterprise license) in milton website are not avaliable. Options 3 should work, but i can't use an empty security manager in my application. So maybe i should use other webdav client except Finder – chou Nov 29 '17 at 03:01
  • You can implement security manager, there are no influence to make this thing work. It`s just for making this without password for testing. Option 1 is availiable, you should contact them and describe for what do you need this – Dmitry Nazarenko Nov 29 '17 at 21:36