Class NearbyFilePayload
- Namespace
- Plugin.Maui.NearbyConnectivity
- Assembly
- Plugin.Maui.NearbyConnectivity.dll
Represents a payload that contains a file.
public sealed class NearbyFilePayload : NearbyPayload, IDisposable
- Inheritance
-
NearbyFilePayload
- Implements
- Inherited Members
Remarks
A received file is staged in app-private, operating-system-purgeable storage, and it is yours from the moment this payload reaches your receive loop. Call MoveTo(string) to keep it, or dispose the payload to delete it now.
A file you neither move nor dispose is deleted when the session is disposed, or the next time the application creates the session. The operating system may reclaim the staging directory before then. Move what you want to keep.
A payload you construct yourself does not own its file: disposing it leaves the file alone.
FileName and ContentType derive from what the sending device supplied. Treat both
as untrusted input: validate the content before acting on the declared type.
Constructors
NearbyFilePayload(FileResult)
Initializes a new instance of the NearbyFilePayload class.
public NearbyFilePayload(FileResult file)
Parameters
fileFileResultThe file that was sent or received.
Properties
File
Gets the file that was sent or received.
public FileResult File { get; }
Property Value
- FileResult
The staged file. After MoveTo(string) this points at the new location.
Methods
MoveTo(string)
Moves the received file out of staging to a location this application owns.
public FileResult MoveTo(string destinationPath)
Parameters
destinationPathstringThe full path to move the file to, file name included. Missing parent directories are created.
Returns
- FileResult
A FileResult for the file at its new location.
Remarks
The move consumes the staged file, so disposing the payload afterwards leaves the moved file alone. Copying the stream instead keeps the staged original until you dispose the payload or the session is disposed. File is updated to point at the new location, so this payload stays usable afterwards.
Within the application sandbox this is a rename and returns immediately, which is why it is synchronous. Call it once per payload. Concurrent calls for the same payload are not supported.
Exceptions
- ArgumentNullException
destinationPathis null.- IOException
A file already exists at
destinationPath, or the file has already been moved, disposed, or purged from staging.- UnauthorizedAccessException
The application cannot write to the destination.