【问题标题】:Objc-C Mongodb Driver to Meteor CollectionFSObjc-C Mongodb 驱动到 Meteor CollectionFS
【发布时间】:2014-01-25 15:49:54
【问题描述】:

我编写了一个objective-c 应用程序,可以将文件写入我的meteor mongodb 数据库。使用 RadMongoDB (https://github.com/timburks/RadMongoDB) 我将图像写入我的 mongo 的 gridfs .files.chunks

//Defining RadMongoDB
RadMongoDB *rad = [[RadMongoDB alloc] init];

//Connection Dictionary
NSDictionary *connection = @{
                             @"host" : @"127.0.0.1",
                             @"port" : [NSNumber numberWithInt:3002]};

int num =[rad connectWithOptions:connection];
[rad writeFile:path2 withMIMEType:@"image/png" inCollection:@"contacts" inDatabase:@"meteor"]

图像(path2)已成功写入gridfs。我是我的meteor mondgodb shell,可以看到文件写入成功了。

.chunks:

.文件:

这些 gridfs 文件链接到一个 collectionfs (https://github.com/CollectionFS/Meteor-CollectionFS) 集合,其中包含通过流星应用程序插入的各种其他图片。问题是使用collectionfs 将驱动程序写入的图像拉出。很明显,驱动程序写入 gridfs 的文件不会被文件处理程序处理。因此,我尝试通过 (collectionfs filehandler reset) 重新强制所有文件,但这仍然不起作用:(Javascript 下面,注意 ContactsFS 是与 gridfs 联系人对应的 collectionfs 集合)。

 //Reset
  ContactsFS.find({}).forEach(function(doc) {
    ContactsFS.update({ _id: doc._id}, { $set: { handledAt: null, fileHandler: {} }  });
  });
  //Set Completed to True
  ContactsFS.update(fileRecord, {$set: {complete: true}});

我得出的结论是,驱动程序与 gridfs 交互的方式与 meteor 和 collectionfs 读取和写入它的方式有很大不同。有没有什么办法解决这一问题?我急需帮助,谢谢!

编辑:

在设置上传的文件complete = true 后,文件处理程序会尝试对驱动程序插入的文件进行操作。但是现在我收到服务器端错误:

我相信这是因为 collectionfs 读取 gridfs 文件的方式。 gridfs 图像的数据由 obj-c 驱动程序存储为 Uint8Array(如屏幕截图 1 所示)。我已经尝试在 obj-c 驱动程序映像上设置每个参数,这样 collectionfs 会很高兴:

ContactsFS.update(imageid, {$set: {handledAt: null}});
ContactsFS.update(imageid, {$set: {uploadDate: date}});
ContactsFS.update(imageid, {$set: {countChunks: 1}});
ContactsFS.update(imageid, {$set: {numChunks: 1}});
ContactsFS.update(imageid, {$set: {length: len}});›
ContactsFS.update(imageid, {$set: {uploading: false}});
ContactsFS.update(imageid, {$set: {encoding: encode}});

//Setting complete to True will send the file through the filehandlers
ContactsFS.update(imageid, {$set: {complete: true}});

还是什么都没有。我该如何解决这个问题?

【问题讨论】:

    标签: objective-c image mongodb meteor gridfs


    【解决方案1】:

    试试这个:

    var len = "" + fileRecord.plength;
    var chunkSize = 256 * 1024; // set this to whatever chunk size RadMongoDB is using
    var chunkCount = Math.ceil(fileRecord.plength / chunkSize);
    
    ContactsFS.update(imageid, {$set: {
      handledAt: null,
      uploadDate: Date.now(),
      countChunks: chunkCount,
      numChunks: chunkCount,
      length: len,
      uploading: false,
      encoding: 'binary'
    }});
    
    ContactsFS.update(imageid, {$set: {complete: true}});
    

    也需要this issue 中讨论的修复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      • 1970-01-01
      • 1970-01-01
      • 2014-05-27
      • 1970-01-01
      相关资源
      最近更新 更多