Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file access problem after upload file #217

Open
meysammeysam74 opened this issue Nov 5, 2022 · 2 comments
Open

file access problem after upload file #217

meysammeysam74 opened this issue Nov 5, 2022 · 2 comments

Comments

@meysammeysam74
Copy link

meysammeysam74 commented Nov 5, 2022

Description: i can not remove file after successfully upload file to server. my error description: The process cannot access the file 'x' because it is being used by another process.
i am using windows service in .netcore.
i am able to remove uploaded file after stop windows service
its important that you upload file with UploadFileAsync method

what are you trying to do
uploading 145mb file to mega server, i am using free account so my speed is limited and its take almost 20 min.

Actual Behavior: i need to be able to remove file from my computer hard drive after successfully upload
what happens
i can not remove the file because it is being used by another process.

Expected Behavior:removing file my computer from hard drive

what should happen
i need to be able to remove uploaded file from my computer

Steps to Reproduce:

  1. new windows service project in .netcore
  2. install MegaApiClient
  3. using static instance from MegaApiClient
  4. using UploadFileAsync method
  5. file need to be large 145 mb and using free mega account
  6. upload need to be take more then 20 min
  7. using windows server 2019
  8. using release version

MegaApiClient Version:1.10.3

@meysammeysam74
Copy link
Author

changing this line of code will fix my problem, can you plz fix this for me ?

from :
public Task<INode> UploadFileAsync(string filename, INode parent, IProgress<double> progress = null, CancellationToken? cancellationToken = null) { return Task.Run(() => { var modificationDate = File.GetLastWriteTime(filename); using (Stream stream = new ProgressionStream(new FileStream(filename, FileMode.Open, FileAccess.Read), progress, _options.ReportProgressChunkSize)) { return Upload(stream, Path.GetFileName(filename), parent, modificationDate, cancellationToken); } }, cancellationToken.GetValueOrDefault()); }

to :
public Task<INode> UploadFileAsync(string filename, INode parent, IProgress<double> progress = null, CancellationToken? cancellationToken = null) { return Task.Run(() => { var modificationDate = File.GetLastWriteTime(filename); var fs = new FileStream(filename, FileMode.Open, FileAccess.Read); using (Stream stream = new ProgressionStream(fs, progress, _options.ReportProgressChunkSize)) { var result = Upload(stream, Path.GetFileName(filename), parent, modificationDate, cancellationToken); fs.Close(); fs = null; return result; } }, cancellationToken.GetValueOrDefault()); }

@meysam25
Copy link

this is exactly why i never using ready components, i always create everything from ziro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@meysam25 @meysammeysam74 and others