Giter VIP home page Giter VIP logo

spring-boot-tus's People

Contributors

thomasooo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

spring-boot-tus's Issues

Chunking and uploading file Gives Exception "The process cannot access the file because it is being used by another process."

Hi,

I am sending one file from browser and uploading to server, it is chunking and uploading to the server.

But while uploading it is giving exception

you can get the github link for the implementation:

) https://github.com/tus/tus-js-client
Spring server implementation
2) https://github.com/thomasooo/spring-boot-tus

java.nio.file.FileSystemException: storage\5b87e2a903751c247c164465: The process cannot access the file because it is being used by another process.

at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:86) ~[?:1.8.0_144]
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97) ~[?:1.8.0_144]
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102) ~[?:1.8.0_144]
at sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:269) ~[?:1.8.0_144]
at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:108) ~[?:1.8.0_144]
at java.nio.file.Files.deleteIfExists(Files.java:1165) ~[?:1.8.0_144]
at java.nio.file.Files.copy(Files.java:3004) ~[?:1.8.0_144]
at tusserver.storage.services.StorageServiceImpl.processStream(StorageServiceImpl.java:84) ~[classes/:?]
at tusserver.StorageController.processPatch(StorageController.java:186) ~[classes/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_144]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_144]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_144]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.11.RELEASE.jar:4.3.11.RELEASE
Code :

public int processStream(String uuid, InputStream inputStream) throws Exception {
String filename = StringUtils.cleanPath(uuid);
File file = new File(storageDir.resolve(filename).toString());

if (!file.isFile()){
    new FileOutputStream(file).close();
    if(!file.isFile()){
        log.error("Cannot create new file");
        throw new TusPermissionDeniedException("Cannot create new file");
    }
}

InputStream storageFile;
try{
    storageFile = new FileInputStream(file);
}catch(IOException e){
    log.error("Cannot read old file");
    throw new TusPermissionDeniedException("Cannot read old file");
}

// File fileToBeInstalled = new File(StorageServiceImpl.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
// Files.copy(fileToBeInstalled.toPath(), storageDir.resolve(filename), StandardCopyOption.REPLACE_EXISTING);
// fileToBeInstalled.delete();

storageFile = new SequenceInputStream(storageFile, inputStream);
// at this position giving exception
Files.copy(storageFile, storageDir.resolve(filename), StandardCopyOption.REPLACE_EXISTING);

file = new File(storageDir.resolve(filename).toString());

return (int) file.length();

}

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.