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

Fixes attachment uploads in Browser context #1064

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fluffy-horses-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@osdk/client": patch
"@osdk/api": patch
---

Fixes attachment upload inputs sending incorrect in browser contexts
4 changes: 3 additions & 1 deletion etc/api.report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ export interface Attachment {
}

// @public
export interface AttachmentUpload extends Blob {
export interface AttachmentUpload {
// (undocumented)
readonly data: Blob;
// (undocumented)
readonly name: string;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/object/Attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ export interface Attachment {
* This interface should also accept the File object from
* the W3C FileApi https://www.w3.org/TR/FileAPI/#file-section
*/
export interface AttachmentUpload extends Blob {
export interface AttachmentUpload {
readonly name: string;
readonly data: Blob;
}

export interface AttachmentMetadata {
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/createClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import { __EXPERIMENTAL__NOT_SUPPORTED_YET__getBulkLinks } from "@osdk/api/unstable";
import { Task } from "@osdk/client.test.ontology";
import * as SharedClientContext from "@osdk/shared.client.impl";
import { mockFetchResponse, MockOntology } from "@osdk/shared.test";
Expand Down
11 changes: 3 additions & 8 deletions packages/client/src/object/AttachmentUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@
import type { AttachmentUpload } from "@osdk/api";

export function isAttachmentUpload(o: any): o is AttachmentUpload {
return o instanceof Blob && "name" in o;
return typeof o === `object` && "name" in o && "data" in o
&& o.data instanceof Blob;
}

export function createAttachmentUpload(
data: Blob,
name: string,
): AttachmentUpload {
const attachmentUpload = Object.create(data, {
name: { value: name },
size: { value: data.size },
type: { value: data.type },
});

return attachmentUpload as AttachmentUpload;
return { data, name };
}
2 changes: 1 addition & 1 deletion packages/client/src/util/toDataValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function toDataValue(
if (isAttachmentUpload(value)) {
const attachment = await OntologiesV2.Attachments.upload(
client,
value,
value.data,
{
filename: value.name,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/util/toDataValueQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function toDataValueQueries(
if (isAttachmentUpload(value)) {
const attachment = await OntologiesV2.Attachments.upload(
client,
value,
value.data,
{
filename: value.name,
},
Expand Down
Loading