Skip to content

Commit b4bedc5

Browse files
committed
Update readme to reflect correct WorkspaceRootPath configuration.
1 parent bbdf4a3 commit b4bedc5

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

README.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -859,17 +859,51 @@ var markItDown = new MarkItDownClient(options);
859859

860860
By default every conversion writes to a unique folder under `.markitdown/` in the current working directory (for example `/app/.markitdown/...`). Those workspaces hold the copied source file, extracted artifacts, and emitted Markdown until the `DocumentConverterResult` is disposed, at which point the directory is deleted. This keeps conversions isolated without leaking data into global temp folders.
861861

862-
You can redirect the workspace to another location—such as the OS temp directory—and opt to keep it after conversion by supplying custom storage options:
862+
You can redirect the workspace root by setting it during app/service initialization (before conversion runs):
863863

864864
```csharp
865865
var workspaceRoot = Path.Combine(Path.GetTempPath(), "markitdown", "workspaces");
866+
Directory.CreateDirectory(workspaceRoot);
867+
868+
builder.Services
869+
.AddMarkItDown()
870+
.UseRootPath(workspaceRoot)
871+
.Configure(options =>
872+
{
873+
options.ArtifactStorage = ArtifactStorageOptions.Default with
874+
{
875+
DeleteOnDispose = false // keep the workspace directory after conversion
876+
};
877+
options.SegmentOptions = SegmentOptions.Default with
878+
{
879+
Image = SegmentOptions.Default.Image with
880+
{
881+
KeepArtifactDirectory = true
882+
}
883+
};
884+
});
885+
```
886+
887+
Then resolve and use `IMarkItDownClient` from DI:
888+
889+
```csharp
890+
await using var scope = app.Services.CreateAsyncScope();
891+
var client = scope.ServiceProvider.GetRequiredService<IMarkItDownClient>();
892+
await using var result = await client.ConvertAsync("policy.pdf");
893+
```
894+
895+
If you do not use DI, configure the same root path directly on `MarkItDownOptions` before creating the first `MarkItDownClient` in the process:
896+
897+
```csharp
898+
var workspaceRoot = Path.Combine(Path.GetTempPath(), "markitdown", "workspaces");
899+
Directory.CreateDirectory(workspaceRoot);
866900

867901
var options = new MarkItDownOptions
868902
{
903+
RootPath = workspaceRoot,
869904
ArtifactStorage = ArtifactStorageOptions.Default with
870905
{
871-
WorkspacePathFormatter = name => Path.Combine(workspaceRoot, name),
872-
DeleteOnDispose = false // keep the workspace directory after conversion
906+
DeleteOnDispose = false // keep the workspace directory after conversion
873907
},
874908
SegmentOptions = SegmentOptions.Default with
875909
{
@@ -880,13 +914,11 @@ var options = new MarkItDownOptions
880914
}
881915
};
882916

883-
Directory.CreateDirectory(workspaceRoot);
884-
885917
await using var client = new MarkItDownClient(options);
886918
await using var result = await client.ConvertAsync("policy.pdf");
887919
```
888920

889-
When you override the workspace root, ensure you manage retention (for example rotate or clean the custom directory) to avoid unbounded growth.
921+
When you override the workspace root, manage retention (for example rotate or clean the custom directory) to avoid unbounded growth.
890922

891923
### Advanced AI Integration
892924

0 commit comments

Comments
 (0)