【问题标题】:EWS: how to get file attachment size before attachment download in iOSEWS:如何在 iOS 中下载附件之前获取文件附件大小
【发布时间】:2026-01-25 18:25:01
【问题描述】:

我正在编写作为邮件客户端的 iOS 应用程序。由于一些限制,我必须使用 EWS(Exchange Web 服务)来处理邮箱。我所能做的就是向服务器发送 SOAP 请求以获取必要的信息。到目前为止,我已经设法使用SyncFolderItems Operation 获取每个文件夹中的邮件列表。之后,我使用GetItem (E-mail Message) Operation 获取每个项目的详细信息。最后一个请求仅返回电子邮件附件 ID 和名称,但不返回它们的大小。但我需要知道它们才能让用户决定是否下载它们。我怎样才能得到这些信息?

这是代码,我在其中创建对服务器的 SOAP 请求。

+(NSString*) syncFolderItems:(NSString*)folderID :(NSString*) syncState 
{
    NSString * syncStateStr=@"<SyncState>%@</SyncState>";
    if(syncState!=nil && ![syncState isEqualToString:@""])
    {
        syncStateStr=[NSString stringWithFormat:syncStateStr,syncState];
    }
    else
        syncStateStr=@"";

    NSString * request= @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"
    "<soap:Body>"
    "<SyncFolderItems xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\">"
    "<ItemShape>"
    "<t:BaseShape>IdOnly</t:BaseShape>"
    "</ItemShape>"
    "<SyncFolderId>"
    "<t:FolderId Id=\"%@\"/>"
    "</SyncFolderId>"
    "%@"
    "<MaxChangesReturned>10</MaxChangesReturned>"
    "</SyncFolderItems>"
    "</soap:Body>"
    "</soap:Envelope>";
    return [NSString stringWithFormat:request, folderID,syncStateStr];
}

+(NSString*)getMailItemsDetails:(NSMutableArray*)items
{
    NSString *request = 
    @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
    "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\">"
    "<soap:Body>"
    "<GetItem xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\">"
    "<ItemShape>"
    "<t:BaseShape>Default</t:BaseShape>"
    "<t:IncludeMimeContent>false</t:IncludeMimeContent>"
        "<t:AdditionalProperties>"
            "<t:FieldURI FieldURI=\"item:Attachments\"/>"
        "</t:AdditionalProperties>"
    "</ItemShape>"
    "<ItemIds>"
    "%@"
    "</ItemIds>"
    "</GetItem>"
    "</soap:Body>"
    "</soap:Envelope>";

    NSString *itemIdTemplate = @"<t:ItemId Id=\"%@\" />";
    NSString *itemsIds = @"";

    for(NSString *msgID in items)
    {
        NSString *itemId = [NSString stringWithFormat:itemIdTemplate, msgID];
        itemsIds = [itemsIds stringByAppendingString:itemId];
    }

    return [NSString stringWithFormat:request, itemsIds];
}

我错过了什么吗? (可能是一些额外的属性?)我必须使用不同的请求吗? EWS 请求有可能吗?如果没有,是否有一些解决方法可以解决问题?任何帮助将不胜感激。

【问题讨论】:

  • 好奇你是否遇到过解决方案。我现在遇到了这个问题

标签: ios soap exchange-server exchangewebservices


【解决方案1】:

Yarlik,按照我的说法,尺寸应该由服务器发送。

不管怎样,让我看看有没有发现,一定要转发给你。

但是,您可以在代表中做一件事,即;

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {

}
-(NSURLRequest *)connection:(NSURLConnection *)connection
        willSendRequest:(NSURLRequest *)request
       redirectResponse:(NSURLResponse *)response {
}

long long fileSize = [response expectedContentLength];

它会给你文件大小。

【讨论】: